local extension = Package:new("new_heg_standard")
extension.extensionName = "new_heg"
extension.game_modes_whitelist = { 'mul_heg_mode', 'ex_heg_mode' }

local heg_mode = require "packages/new_heg/new_heg"
extension:addGameMode(heg_mode)

local mul_heg_mode = require "packages/new_heg/nos_new_heg"
extension:addGameMode(mul_heg_mode)

local H = require "packages/new_heg/util"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["new_heg_standard"] = "国战标准版",
  ["hs"] = "国标",
}

-----
local caocao = General(extension, "hs__n_caocao", "wei", 4)
caocao:addCompanions({"hs__n_dianwei", "hs__n_xuchu"})
local jianxiong = fk.CreateTriggerSkill{
  name = "hs__n_jianxiong",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and player.room:getCardArea(data.card) == Card.Processing
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
  end,
}
caocao:addSkill(jianxiong)
Fk:loadTranslationTable{
  ["hs__n_caocao"] = "曹操",
  ["#hs__n_caocao"] = "魏武帝",

  ["hs__n_jianxiong"] = "奸雄",
  [":hs__n_jianxiong"] = "当你受到伤害后，你可获得对你造成伤害的牌。",
  
  ["$hs__n_jianxiong1"] = "宁教我负天下人，休教天下人负我！",
  ["$hs__n_jianxiong2"] = "吾好梦中杀人！",
  ["~hs__n_caocao"] = "霸业未成，未成啊……",
}

-----
local simayi = General(extension, "hs__n_simayi", "wei", 3)
local fankui = fk.CreateTriggerSkill{
  name = "hs__n_fankui",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.from and not data.from.dead then
      if data.from == player then
        return #player.player_cards[Player.Equip] > 0
      else
        return not data.from:isNude()
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = data.from
    local flag =  from == player and "e" or "he"
    local card = room:askForCardChosen(player, from, flag, self.name)
    room:obtainCard(player.id, card, false, fk.ReasonPrey)
  end
}
local guicai = fk.CreateTriggerSkill{
  name = "hs__n_guicai",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local card = room:askForCard(player, 1, 1, true, self.name, true, ".|.|.|hand,equip", "#hs__n_guicai-ask::" .. target.id .. ":" .. data.reason)
    if #card > 0 then
      room:doIndicate(player.id, {target.id})
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:retrial(Fk:getCardById(self.cost_data), player, data, self.name)
  end,
}
simayi:addSkill(fankui)
simayi:addSkill(guicai) -- 手杀
Fk:loadTranslationTable{
  ["hs__n_simayi"] = "司马懿",
  ["#hs__n_simayi"] = "狼顾之鬼",
  ["illustrator:hs__n_simayi"] = "木美人",

  ["hs__n_fankui"] = "反馈",
  [":hs__n_fankui"] = "当你受到伤害后，你可获得伤害来源的一张牌。",
  ["hs__n_guicai"] = "鬼才",
  [":hs__n_guicai"] = "当判定结果确定前，你可打出一张牌代替之。",
  ["#hs__n_guicai-ask"] = "鬼才：你可打出一张牌代替 %dest 的 %arg 判定",

  ["$hs__n_guicai1"] = "天命？哈哈哈哈……",
  ["$hs__n_guicai2"] = "吾乃天命之子！",
  ["$hs__n_fankui1"] = "下次注意点。",
  ["$hs__n_fankui2"] = "出来混，早晚要还的。",
  ["~hs__n_simayi"] = "我的气数就到这里了吗？",
}

-----
local xiahoudun = General(extension, "hs__n_xiahoudun", "wei", 4)
xiahoudun:addCompanions("hs__n_xiahouyuan")
local hs__n_ganglie = fk.CreateTriggerSkill{
  name = "hs__n_ganglie",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self:doCost(event, target, player, data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = data.from
    if from and not from.dead then room:doIndicate(player.id, {from.id}) end
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if judge.card.color == Card.Red and from and not from.dead then
      room:damage{
        from = player,
        to = from,
        damage = 1,
        skillName = self.name,
      }
    elseif judge.card.color == Card.Black and from and not from:isNude() then
      local cid = room:askForCardChosen(player, from, "he", self.name)
      room:throwCard({cid}, self.name, from, player)
    end
  end
}
xiahoudun:addSkill(hs__n_ganglie)
Fk:loadTranslationTable{
  ["hs__n_xiahoudun"] = "夏侯惇",
  ["#hs__n_xiahoudun"] = "独眼的罗刹",
  ["illustrator:hs__n_xiahoudun"] = "DH",

  ["hs__n_ganglie"] = "刚烈",
  [":hs__n_ganglie"] = "当你受到伤害后，你可判定，若结果为：红色，你对来源造成1点伤害；黑色，你弃置来源的一张牌。",

  ["$hs__n_ganglie1"] = "鼠辈，竟敢伤我！",
  ["$hs__n_ganglie2"] = "以彼之道，还施彼身！",
  ["~hs__n_xiahoudun"] = "诸多败绩，有负丞相重托……",
}

-----
local zhangliao = General(extension, "hs__n_zhangliao", "wei", 4)
local hs__n_tuxi = fk.CreateTriggerSkill{
  name = "hs__n_tuxi",
  anim_type = "control",
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.n > 0 and
      table.find(player.room:getOtherPlayers(player, false), function(p) return not p:isKongcheng() end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
      return not p:isKongcheng() end), Util.IdMapper)
    local tos = room:askForChoosePlayers(player, targets, 1, data.n, "#hs__n_tuxi-choose:::"..data.n, self.name, true)
    if #tos > 0 then
       room:sortPlayersByAction(tos)
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = table.simpleClone(self.cost_data.tos)
    for _, id in ipairs(tos) do
      local to = room:getPlayerById(id)
      if not (to.dead or to:isKongcheng()) then
        local c = room:askForCardChosen(player, to, "h", self.name)
        room:obtainCard(player, c, false, fk.ReasonPrey)
        if player.dead then break end
      end
    end
    data.n = data.n - #tos
  end,
}
zhangliao:addSkill(hs__n_tuxi)
Fk:loadTranslationTable{
  ["hs__n_zhangliao"] = "张辽",
  ["#hs__n_zhangliao"] = "前将军",
  ["illustrator:hs__n_zhangliao"] = "张帅",

  ["hs__n_tuxi"] = "突袭",
  [":hs__n_tuxi"] = "摸牌阶段，你可以少摸任意张牌并获得等量其他角色各一张手牌。",
  ["#hs__n_tuxi-choose"] = "突袭：你可以少摸至多%arg张牌，获得等量其他角色各一张手牌",

  ["$hs__n_tuxi1"] = "哼，没想到吧！",
  ["$hs__n_tuxi2"] = "拿来吧！",
  ["~hs__n_zhangliao"] = "被敌人占了先机……呃……",
}

-----
local xuchu = General(extension, "hs__n_xuchu", "wei", 4)
local hs__n_luoyi = fk.CreateTriggerSkill{
  name = "hs__n_luoyi",
  anim_type = "offensive",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
  end,
  on_use = function(self, event, target, player, data)
    player.room:askForDiscard(player, 1, 1, false, self.name, false, nil, "hs__n_luoyi-ask", false)
  end,
}
local hs__n_luoyi_trigger = fk.CreateTriggerSkill{
  name = "#hs__n_luoyi_trigger",
  mute = true,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:usedSkillTimes("hs__n_luoyi", Player.HistoryTurn) > 0 and
      not data.chain and data.card and (data.card.trueName == "slash" or data.card.name == "duel")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("hs__n_luoyi")
    room:notifySkillInvoked(player, "hs__n_luoyi")
    data.damage = data.damage + 1
  end,
}
hs__n_luoyi:addRelatedSkill(hs__n_luoyi_trigger)
xuchu:addSkill(hs__n_luoyi)
Fk:loadTranslationTable{
  ["hs__n_xuchu"] = "许褚",
  ["#hs__n_xuchu"] = "虎痴",
  ["illustrator:hs__n_xuchu"] = "KayaK",

  ["hs__n_luoyi"] = "裸衣",
  [":hs__n_luoyi"] = "摸牌阶段结束时，你可弃置一张牌，令你于此回合内执行【杀】或【决斗】的效果造成伤害时，此伤害+1。",
  ["hs__n_luoyi-ask"] = "裸衣：你可弃置一张牌，于此回合内执行【杀】或【决斗】的效果造成伤害时伤害+1",

  ["$hs__n_luoyi1"] = "脱！",
  ["$hs__n_luoyi2"] = "谁来与我大战三百回合？",
  ["~hs__n_xuchu"] = "冷，好冷啊……",
}

-----
local guojia = General(extension, "hs__n_guojia", "wei", 3)
local hs__n_yiji_active = fk.CreateActiveSkill{
  name = "hs__n_yiji_active",
  expand_pile = function(self)
    return Self:getTableMark("hs__n_yiji_cards")
  end,
  min_card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected, targets)
    local ids = Self:getMark("hs__n_yiji_cards")
      return type(ids) == "table" and table.contains(ids, to_select)
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
}
local yiji = fk.CreateTriggerSkill{
  name = "hs__n_yiji",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = room:getNCards(2)
    while true do
      room:setPlayerMark(player, "hs__n_yiji_cards", ids)
      local _, ret = room:askForUseActiveSkill(player, "hs__n_yiji_active", "#hs__n_yiji-give", true, nil, true)
      room:setPlayerMark(player, "hs__n_yiji_cards", 0)
      if ret then
        for _, id in ipairs(ret.cards) do
          table.removeOne(ids, id)
        end
        room:moveCardTo(ret.cards, Card.PlayerHand, room:getPlayerById(ret.targets[1]), fk.ReasonGive, self.name, nil, false, player.id)
        if #ids == 0 then break end
        if player.dead then
          room:moveCards({
            ids = ids,
            toArea = Card.DiscardPile,
            moveReason = fk.ReasonJustMove,
            skillName = self.name,
          })
          break
        end
      else
        room:moveCardTo(ids, Player.Hand, player, fk.ReasonGive, self.name, nil, false, player.id)
        break
      end
    end
  end,
}
local tiandu = fk.CreateTriggerSkill{
  name = "hs__n_tiandu",
  anim_type = "drawcard",
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.room:getCardArea(data.card) == Card.Processing
  end,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
  end,
}
Fk:addSkill(hs__n_yiji_active)
guojia:addSkill(tiandu)
guojia:addSkill(yiji)
Fk:loadTranslationTable{
  ["hs__n_guojia"] = "郭嘉",
  ["#hs__n_guojia"] = "早终的先知",
  ["illustrator:hs__n_guojia"] = "绘聚艺堂",

  ["hs__n_yiji"] = "遗计",
  [":hs__n_yiji"] = "当你受到伤害后，你可观看牌堆顶的两张牌并分配。",
  ["hs__n_tiandu"] = "天妒",
  [":hs__n_tiandu"] = "当你的判定牌生效后，你可获得之。",
  ["#hs__n_yiji-give"] = "遗计：你可以将这些牌分配给其他角色，或点“取消”自己保留",
  ["hs__n_yiji_active"] = "遗计",

  ["$hs__n_yiji1"] = "也好。",
  ["$hs__n_yiji2"] = "罢了。",
  ["$hs__n_tiandu1"] = "就这样吧。",
  ["$hs__n_tiandu2"] = "哦？",
  ["~hs__n_guojia"] = "咳，咳……",
}

-----
local zhenji = General(extension, "hs__n_zhenji", "wei", 3, 3, General.Female)
zhenji:addCompanions("hs__n_caopi")
local luoshen = fk.CreateTriggerSkill{
  name = "hs__n_luoshen",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cardsJudged = {}
    while true do
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|spade,club",
        skipDrop = true,
      }
      room:judge(judge)
      local card = judge.card
      if card.color == Card.Black then
        table.insert(cardsJudged, card)
      elseif room:getCardArea(card) == Card.Processing then
        room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player.id)
      end
      if card.color ~= Card.Black or player.dead or not room:askForSkillInvoke(player, self.name) then
        break
      end
    end
    cardsJudged = table.filter(cardsJudged, function(c) return room:getCardArea(c.id) == Card.Processing end)
    if #cardsJudged > 0 then
      room:obtainCard(player, table.map(cardsJudged, function(card)
        return card.id
      end), true, fk.ReasonJustMove)
    end
  end,
}
local qingguo = fk.CreateViewAsSkill{
  name = "hs__n_qingguo",
  anim_type = "defensive",
  pattern = "jink",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).color == Card.Black
      and Fk:currentRoom():getCardArea(to_select) == Player.Hand
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("jink")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
zhenji:addSkill(luoshen)
zhenji:addSkill(qingguo)
Fk:loadTranslationTable{
  ["hs__n_zhenji"] = "甄姬",
  ["#hs__n_zhenji"] = "薄幸的美人",
  ["illustrator:hs__n_zhenji"] = "DH",

  ["hs__n_luoshen"] = "洛神",
  [":hs__n_luoshen"] = "准备阶段，你可进行判定，你可重复此流程，直到判定结果为红色，然后你获得所有黑色的判定牌。",
  ["hs__n_qingguo"] = "倾国",
  [":hs__n_qingguo"] = "你可以将一张黑色手牌当【闪】使用或打出。",

  ["$hs__n_qingguo1"] = "凌波微步，罗袜生尘。",
  ["$hs__n_qingguo2"] = "体迅飞凫，飘忽若神。",
  ["$hs__n_luoshen1"] = "髣髴兮若轻云之蔽月。",
  ["$hs__n_luoshen2"] = "飘飖兮若流风之回雪。",
  ["~hs__n_zhenji"] = "悼良会之永绝兮，哀一逝而异乡。",
}

-----
local xiahouyuan = General(extension, "hs__n_xiahouyuan", "wei", 5)
local shensu = fk.CreateTriggerSkill{
  name = "hs__n_shensu",
  anim_type = "offensive",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and not player:prohibitUse(Fk:cloneCard("slash")) then
      if (data.to == Player.Judge and not player.skipped_phases[Player.Draw]) or data.to == Player.Discard then
        return true
      elseif data.to == Player.Play then
        return not player:isNude()
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local slash = Fk:cloneCard("slash")
    local max_num = slash.skill:getMaxTargetNum(player, slash)
    local targets = {}
    for _, p in ipairs(room:getOtherPlayers(player, false)) do
      if not player:isProhibited(p, slash) then
        table.insert(targets, p.id)
      end
    end
    if #targets == 0 or max_num == 0 then return end
    if data.to == Player.Judge then
      local tos = room:askForChoosePlayers(player, targets, 1, max_num, "#hs__n_shensu1-choose", self.name, true)
      if #tos > 0 then
        self.cost_data = {tos}
        return true
      end
    elseif data.to == Player.Play then
      local tos, id = room:askForChooseCardAndPlayers(player, targets, 1, max_num, ".|.|.|.|.|equip", "#hs__n_shensu2-choose", self.name, true)
      if #tos > 0 and id then
        self.cost_data = {tos, {id}}
        return true
      end
    elseif data.to == Player.Discard then
      local tos = room:askForChoosePlayers(player, targets, 1, max_num, "#hs__n_shensu3-choose", self.name, true)
      if #tos > 0 then
        self.cost_data = {tos}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.to == Player.Judge then
      player:skip(Player.Judge)
      player:skip(Player.Draw)
    elseif data.to == Player.Play then
      player:skip(Player.Play)
      room:throwCard(self.cost_data[2], self.name, player, player)
    elseif data.to == Player.Discard then
      player:skip(Player.Discard)
      player.room:loseHp(player, 1, self.name)
    end

    local slash = Fk:cloneCard("slash")
    slash.skillName = self.name
    room:useCard({
      from = target.id,
      tos = table.map(self.cost_data[1], function(pid) return { pid } end),
      card = slash,
      extraUse = true,
    })
    return true
  end,
}
xiahouyuan:addSkill(shensu)
Fk:loadTranslationTable{
  ["hs__n_xiahouyuan"] = "夏侯渊",
  ["#hs__n_xiahouyuan"] = "虎步关右",
  ["illustrator:hs__n_xiahouyuan"] = "凡果",

  ["hs__n_shensu"] = "神速",
  [":hs__n_shensu"] = "①判定阶段开始前，你可跳过此阶段和摸牌阶段视为使用普【杀】。②出牌阶段开始前，你可跳过此阶段并弃置一张装备牌视为使用普【杀】。③弃牌阶段开始前，你可跳过此阶段并失去1点体力视为使用普【杀】。",
  ["#hs__n_shensu1-choose"] = "神速：你可以跳过判定阶段和摸牌阶段，视为使用一张无距离限制的【杀】",
  ["#hs__n_shensu2-choose"] = "神速：你可以跳过出牌阶段并弃置一张装备牌，视为使用一张无距离限制的【杀】",
  ["#hs__n_shensu3-choose"] = "神速：你可以跳过弃牌阶段并失去1点体力，视为使用一张无距离限制的【杀】",

  ["$hs__n_shensu1"] = "吾善于千里袭人！",
  ["$hs__n_shensu2"] = "取汝首级，有如探囊取物！",
  ["~hs__n_xiahouyuan"] = "竟然比我还…快……",
}

-----
local zhanghe = General(extension, "hs__n_zhanghe", "wei", 4)
local qiaobian = fk.CreateTriggerSkill{
  name = "hs__n_qiaobian",
  anim_type = "offensive",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isKongcheng() and
    data.to > Player.Start and data.to < Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, ".", "#hs__n_qiaobian-invoke:::" .. Util.PhaseStrMapper(data.to), true)
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
    player:skip(data.to)
    if data.to == Player.Draw then
      local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
        return not p:isKongcheng() end), Util.IdMapper)
      if #targets > 0 then
        local n = math.min(2, #targets)
        local tos = room:askForChoosePlayers(player, targets, 1, n, "#hs__n_qiaobian-choose:::"..n, self.name, true)
        if #tos > 0 then
          room:sortPlayersByAction(tos)
          for _, id in ipairs(tos) do
            local p = room:getPlayerById(id)
            if not p:isKongcheng() then
              local card_id = room:askForCardChosen(player, p, "h", self.name)
              room:obtainCard(player, card_id, false, fk.ReasonPrey)
            end
          end
        end
      end
    elseif data.to == Player.Play then
      local targets = room:askForChooseToMoveCardInBoard(player, "#hs__n_qiaobian-move", self.name, true, nil)
      if #targets ~= 0 then
        targets = table.map(targets, function(id) return room:getPlayerById(id) end)
        room:askForMoveCardInBoard(player, targets[1], targets[2], self.name)
      end
    end
    return true
  end,
}
zhanghe:addSkill(qiaobian)
Fk:loadTranslationTable{
  ["hs__n_zhanghe"] = "张郃",
  ["#hs__n_zhanghe"] = "料敌机先",
  ["illustrator:hs__n_zhanghe"] = "张帅",

  ["hs__n_qiaobian"] = "巧变",
  [":hs__n_qiaobian"] = "你的阶段开始前（准备阶段和结束阶段除外），你可弃置一张手牌跳过该阶段。若以此法跳过摸牌阶段，"..
  "你可获得至多两名其他角色的各一张手牌；若以此法跳过出牌阶段，你可将场上的一张牌移动至另一名角色相应的区域内。",
  ["#hs__n_qiaobian-invoke"] = "巧变：你可以弃一张手牌，跳过 %arg",
  ["#hs__n_qiaobian-choose"] = "巧变：你可以依次获得%arg名角色的各一张手牌",
  ["#hs__n_qiaobian-move"] = "巧变：请选择两名角色，移动场上的一张牌",

  ["$hs__n_qiaobian1"] = "兵无常势，水无常形。",
  ["$hs__n_qiaobian2"] = "用兵之道，变化万千。",
  ["~hs__n_zhanghe"] = "呃，膝盖中箭了……",
}

-----
local xuhuang = General(extension, "hs__n_xuhuang", "wei", 4)
local duanliang = fk.CreateViewAsSkill{
  name = "hs__n_duanliang",
  anim_type = "control",
  pattern = "supply_shortage",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black and Fk:getCardById(to_select).type ~= Card.TypeTrick
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("supply_shortage")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  before_use = function(self, player, use)
    local targets = TargetGroup:getRealTargets(use.tos)
    if #targets == 0 then return end
    local room = player.room
    for _, p in ipairs(targets) do
      if player:distanceTo(room:getPlayerById(p)) > 2 then
        room:invalidateSkill(player, self.name, "-phase")
        room:setPlayerMark(player, "@@hs__n_duanliang-phase", 1)
      end
    end
  end
}
local duanliang_targetmod = fk.CreateTargetModSkill{
  name = "#hs__n_duanliang_targetmod",
  bypass_distances = function (self, player, skill, card, to)
    return player:hasSkill(duanliang) and skill.trueName == "supply_shortage_skill"
  end
}
duanliang:addRelatedSkill(duanliang_targetmod)
xuhuang:addSkill(duanliang)
Fk:loadTranslationTable{
  ["hs__n_xuhuang"] = "徐晃",
  ["#hs__n_xuhuang"] = "周亚夫之风",
  ["illustrator:hs__n_xuhuang"] = "Tuu.",

  ["hs__n_duanliang"] = "断粮",
  [":hs__n_duanliang"] = "你可将一张不为锦囊牌的黑色牌当无距离限制的【兵粮寸断】使用，若你至目标对应的角色的距离大于2，此技能于此阶段内无效。",
  ["@@hs__n_duanliang-phase"] = "断粮 无效",

  ["$hs__n_duanliang1"] = "截其源，断其粮，贼可擒也。",
  ["$hs__n_duanliang2"] = "人是铁，饭是钢。",
  ["~hs__n_xuhuang"] = "一顿不吃饿得慌。",
}

-----
local caoren = General(extension, "hs__n_caoren", "wei", 4)
local jushou_select = fk.CreateActiveSkill{
  name = "#hs__n_jushou_select",
  can_use = Util.FalseFunc,
  target_num = 0,
  card_num = 1,
  card_filter = function(self, to_select, selected)
    if #selected == 0 and Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip then
      local card = Fk:getCardById(to_select)
      if card.type == Card.TypeEquip then
        return not Self:prohibitUse(card)
      else
        return not Self:prohibitDiscard(card)
      end
    end
  end,
}
local jushou = fk.CreateTriggerSkill{
  name = "hs__n_jushou",
  anim_type = "defensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = 0
    for _, v in pairs(H.getKingdomPlayersNum(room)) do
      if v and v > 0 then
        num = num + 1
      end
    end
    room:drawCards(player, num, self.name)
    if player.dead then return false end
    local jushou_card
    for _, id in pairs(player:getCardIds(Player.Hand)) do
      local card = Fk:getCardById(id)
      if (card.type == Card.TypeEquip and not player:prohibitUse(card)) or (card.type ~= Card.TypeEquip and not player:prohibitDiscard(card)) then
        jushou_card = card
        break
      end
    end
    if not jushou_card then return end
    local _, ret = room:askForUseActiveSkill(player, "#hs__n_jushou_select", "#hs__n_jushou-select", false)
    if ret then
      jushou_card = Fk:getCardById(ret.cards[1])
    end
    if jushou_card then
      if jushou_card.type == Card.TypeEquip then
        room:useCard({
          from = player.id,
          tos = {{player.id}},
          card = jushou_card,
        })
      else
        room:throwCard(jushou_card:getEffectiveId(), self.name, player, player)
      end
    end
    if player.dead then return false end
    if num > 2 then player:turnOver() end
  end,
}
jushou:addRelatedSkill(jushou_select)
caoren:addSkill(jushou)
Fk:loadTranslationTable{
  ["hs__n_caoren"] = "曹仁",
  ["#hs__n_caoren"] = "大将军",
  ["illustrator:hs__n_caoren"] = "Ccat",

  ["hs__n_jushou"] = "据守",
  [":hs__n_jushou"] = "结束阶段，你可摸X张牌（X为势力数），然后弃置一张手牌，若以此法弃置的牌为装备牌，则改为你使用之。若X大于2，则你将武将牌叠置。",
  ["#hs__n_jushou_select"] = "据守",
  ["#hs__n_jushou-select"] = "据守：选择使用手牌中的一张装备牌或弃置手牌中的一张非装备牌",

  ["$hs__n_jushou1"] = "我先休息一会儿！",
  ["$hs__n_jushou2"] = "尽管来吧！",
  ["~hs__n_caoren"] = "实在是守不住了……",
}

-----
local dianwei = General(extension, "hs__n_dianwei", "wei", 4)
local hs__n_qiangxi = fk.CreateActiveSkill{
  name = "hs__n_qiangxi",
  anim_type = "offensive",
  max_card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return Fk:getCardById(to_select).sub_type == Card.SubtypeWeapon
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    if #effect.cards > 0 then
      room:throwCard(effect.cards, self.name, player)
    else
      room:loseHp(player, 1, self.name)
    end
    room:damage{
      from = player,
      to = target,
      damage = 1,
      skillName = self.name,
    }
  end,
}
dianwei:addSkill(hs__n_qiangxi)
Fk:loadTranslationTable{
  ['hs__n_dianwei'] = '典韦',
  ["#hs__n_dianwei"] = "古之恶来",
  ["illustrator:hs__n_dianwei"] = "凡果",

  ["hs__n_qiangxi"] = "强袭",
  [":hs__n_qiangxi"] = "出牌阶段限一次，你可以失去1点体力或弃置一张武器牌，并选择一名其他角色，对其造成1点伤害。",

  ["$hs__n_qiangxi1"] = "吃我一戟！",
  ["$hs__n_qiangxi2"] = "看我三步之内取你小命！",
  ["~hs__n_dianwei"] = "主公，快走！",
}

-----
local xunyu = General(extension, "hs__n_xunyu", "wei", 3)
local jieming = fk.CreateTriggerSkill{
  name = "hs__n_jieming",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#hs__n_jieming-choose", self.name, true)
    if #to > 0 then
      self.cost_data = {tos = to}
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(self.cost_data.tos[1])
    local num = math.min(to.maxHp, 5) - to:getHandcardNum()
    if num > 0 then
      to:drawCards(num, self.name)
    end
  end,
}
local quhu = fk.CreateActiveSkill{
  name = "hs__n_quhu",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and Self:canPindian(target) and target.hp > Self.hp
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player then
      local targets = {}
      for _, p in ipairs(room:getOtherPlayers(target)) do
        if target:inMyAttackRange(p) then
          table.insert(targets, p.id)
        end
      end
      if #targets == 0 then return end
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#hs__n_quhu-choose", self.name)
      room:damage{
        from = target,
        to = room:getPlayerById(tos[1]),
        damage = 1,
        skillName = self.name,
      }
    else
      room:damage{
        from = target,
        to = player,
        damage = 1,
        skillName = self.name,
      }
    end
  end,
}
xunyu:addSkill(quhu)
xunyu:addSkill(jieming)
Fk:loadTranslationTable{
  ['hs__n_xunyu'] = '荀彧',
  ["#hs__n_xunyu"] = "王佐之才",
  ["illustrator:hs__n_xunyu"] = "LiuHeng",

  ["hs__n_quhu"] = "驱虎",
  [":hs__n_quhu"] = "出牌阶段限一次，你可以与一名体力值大于你的角色拼点。若你赢，该角色对其攻击范围内你指定的另一名角色造成1点伤害；若你没赢，其对你造成1点伤害。",
  ["hs__n_jieming"] = "节命",
  [":hs__n_jieming"] = "当你受到伤害后，你可令一名角色将手牌补至X张（X为其体力上限且最多为5）。",
  ["#hs__n_quhu-choose"] = "驱虎：选择其攻击范围内的一名角色，其对此角色造成1点伤害",
  ["#hs__n_jieming-choose"] = "节命：令一名角色将手牌补至X张（X为其体力上限且最多为5）",

  ["$hs__n_quhu1"] = "此乃驱虎吞狼之计。",
  ["$hs__n_quhu2"] = "借你之手，与他一搏吧。",
  ["$hs__n_jieming1"] = "秉忠贞之志，守谦退之节。",
  ["$hs__n_jieming2"] = "我，永不背弃。",
  ["~hs__n_xunyu"] = "主公要臣死，臣不得不死。",
}

-----
local caopi = General(extension, "hs__n_caopi", "wei", 3)
local fangzhu = fk.CreateTriggerSkill{
  name = "hs__n_fangzhu",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player, false), Util.IdMapper), 1, 1, "#hs__n_fangzhu-choose:::"..player:getLostHp(), self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local num = player:getLostHp()
    if to.hp > 0 and #room:askForDiscard(to, num, num, true, self.name, true, nil, "hs__n_fangzhu_ask:::" .. num, false) > 0 then
      if not to.dead then room:loseHp(to, 1, self.name) end
    else
      to:drawCards(num, self.name)
      if not to.dead then to:turnOver() end
    end
  end,
}
local xingshang = fk.CreateTriggerSkill{
  name = "hs__n_xingshang",
  anim_type = "drawcard",
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not target:isNude()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards_id = target:getCardIds{Player.Hand, Player.Equip}
    room:obtainCard(player.id, cards_id, false, fk.ReasonPrey)
  end,
}
caopi:addSkill(xingshang)
caopi:addSkill(fangzhu)
Fk:loadTranslationTable{
  ['hs__n_caopi'] = '曹丕',
  ["#hs__n_caopi"] = "霸业的继承者",
  ["illustrator:hs__n_caopi"] = "DH",

  ["hs__n_xingshang"] = "行殇",
  [":hs__n_xingshang"] = "当其他角色死亡时，你可以获得其所有牌。",
  ["hs__n_fangzhu"] = "放逐",
  [":hs__n_fangzhu"] = "当你受到伤害后，你可令一名其他角色选择一项：1.摸X张牌并叠置；2.弃置X张牌并失去1点体力。（X为你已损失的体力值）",
  ["#hs__n_fangzhu-choose"] = "放逐：你可令一名其他角色选择摸%arg张牌并叠置，或弃置等量张牌并失去1点体力",
  ["hs__n_fangzhu_ask"] = "放逐：弃置%arg张牌并失去1点体力，或点击“取消”，摸牌并叠置",

  ["$hs__n_xingshang1"] = "我的是我的，你的还是我的。",
  ["$hs__n_xingshang2"] = "来，管杀还管埋！",
  ["$hs__n_fangzhu1"] = "死罪可免，活罪难赦！",
  ["$hs__n_fangzhu2"] = "给我翻过来！",
  ["~hs__n_caopi"] = "子建，子建……",
}

-----
local yuejin = General(extension, "hs__n_yuejin", "wei", 4)
local xiaoguo = fk.CreateTriggerSkill{
  name = "hs__n_xiaoguo",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and target.phase == Player.Finish and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|.|.|.|basic", "#hs__n_xiaoguo-invoke::"..target.id, true)
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
    if #room:askForDiscard(target, 1, 1, true, self.name, true, ".|.|.|.|.|equip", "#hs__n_xiaoguo-discard:"..player.id) == 0 then
      room:damage{
        from = player,
        to = target,
        damage = 1,
        skillName = self.name,
      }
    elseif not player.dead then
      player:drawCards(1, self.name)
    end
  end,
}
yuejin:addSkill(xiaoguo)
Fk:loadTranslationTable{
  ["hs__n_yuejin"] = "乐进",
  ["#hs__n_yuejin"] = "奋强突固",
  ["illustrator:hs__n_yuejin"] = "巴萨小马",
  ["desinger:hs__n_yuejin"] = "淬毒",

  ["hs__n_xiaoguo"] = "骁果",
  [":hs__n_xiaoguo"] = "其他角色的结束阶段，你可弃置一张基本牌，然后其选择一项：1.弃置一张装备牌，然后你摸一张牌；2.你对其造成1点伤害。",
  ["#hs__n_xiaoguo-invoke"] = "骁果：你可以弃置一张基本牌，%dest 需弃置一张装备牌，否则你对其造成1点伤害",
  ["#hs__n_xiaoguo-discard"] = "骁果：你需弃置一张装备牌，否则 %src 对你造成1点伤害",

  ["$hs__n_xiaoguo1"] = "三军听我号令，不得撤退！",
  ["$hs__n_xiaoguo2"] = "看我先登城头，立下首功！",
  ["~hs__n_yuejin"] = "箭疮发作，吾命休矣。",
}

---------------------
-----
local liubei = General(extension, "hs__n_liubei", "shu", 4)
liubei:addCompanions({"hs__n_guanyu", "hs__n_zhangfei", "hs__n_ganfuren"})
local rende = fk.CreateActiveSkill{
  name = "hs__n_rende",
  anim_type = "support",
  min_card_num = 1,
  target_num = 1,
  prompt = "#ex__rende",
  card_filter = function(self, to_select, selected)
    return table.contains(Self:getCardIds("h"), to_select)
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("_ex__rende-phase") == 0
  end,
  on_use = function(self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    local player = room:getPlayerById(effect.from)
    local cards = effect.cards
    local marks = player:getMark("_rende_cards-phase")
    room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, self.name, nil, false)
    room:addPlayerMark(player, "_rende_cards-phase", #cards)
    room:setPlayerMark(target, "_ex__rende-phase", 1)
    if marks < 2 and marks + #cards >= 2 then
      cards = U.getUniversalCards(room, "b", false)
      local use = U.askForUseRealCard(room, player, cards, nil, self.name, "#ex__rende-ask",
        {expand_pile = cards, bypass_times = false, extraUse = false}, true, true)
      if use then
        use = {
          card = Fk:cloneCard(use.card.name),
          from = player.id,
          tos = use.tos,
        }
        use.card.skillName = self.name
        room:useCard(use)
      end
    end
  end,
}
liubei:addSkill(rende)
Fk:loadTranslationTable{
  ["hs__n_liubei"] = "刘备",
  ["#hs__n_liubei"] = "乱世的枭雄",
  ["illustrator:hs__n_liubei"] = "木美人",

  ["hs__n_rende"] = "仁德",
  [":hs__n_rende"] = "出牌阶段每名角色限一次，你可以将任意张手牌交给一名其他角色，当你以此法给出第二张牌后，你可以视为使用一张基本牌。",
  ["#ex__rende"] = "仁德：将任意张手牌交给一名角色，若此阶段交出达到两张，你可以视为使用一张基本牌",
  ["#ex__rende-ask"] = "仁德：你可视为使用一张基本牌",

  ["$hs__n_rende1"] = "以德服人。",
  ["$hs__n_rende2"] = "施仁布泽，乃我大汉立国之本。",
  ["~hs__n_liubei"] = "汉室未兴，祖宗未耀，朕实不忍此时西去……",
}

-----
local guanyu = General(extension, "hs__n_guanyu", "shu", 5)
guanyu:addCompanions("hs__n_zhangfei")
local wusheng = fk.CreateViewAsSkill{
  name = "hs__n_wusheng",
  anim_type = "offensive",
  pattern = "slash",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return (H.getHegLord(Fk:currentRoom(), Self) and H.getHegLord(Fk:currentRoom(), Self):hasSkill("ld__n_shouyue")) or Fk:getCardById(to_select).color == Card.Red
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
local wusheng_targetmod = fk.CreateTargetModSkill{
  name = "#hs__n_wusheng_targetmod",
  anim_type = "offensive",
  bypass_distances = function (self, player, skill, card, to)
    return card and player:hasSkill(wusheng) and skill.trueName == "slash_skill" and card.suit == Card.Diamond
  end
}
wusheng:addRelatedSkill(wusheng_targetmod)
guanyu:addSkill(wusheng)
Fk:loadTranslationTable{
  ["hs__n_guanyu"] = "关羽",
  ["#hs__n_guanyu"] = "威震华夏",
  ["illustrator:hs__n_guanyu"] = "凡果",

  ["hs__n_wusheng"] = "武圣",
  [":hs__n_wusheng"] = "你可将一张红色牌当【杀】使用或打出。你使用方块【杀】无距离限制。",

  ["$hs__n_wusheng1"] = "关羽在此，尔等受死！",
  ["$hs__n_wusheng2"] = "看尔乃插标卖首！",
  ["~hs__n_guanyu"] = "什么？此地名叫麦城？",
}

-----
local zhangfei = General(extension, "hs__n_zhangfei", "shu", 4)
local paoxiao = fk.CreateTargetModSkill{
  name = "hs__n_paoxiao",
  frequency = Skill.Compulsory,
  bypass_times = function(self, player, skill, scope, card)
    if card and player:hasSkill(self) and skill.trueName == "slash_skill"
      and scope == Player.HistoryPhase then
      return true
    end
  end,
}
local paoxiaoTrigger = fk.CreateTriggerSkill{
  name = "#hs__n_paoxiaoTrigger",
  events = {fk.CardUsing},
  anim_type = "offensive",
  visible = false,
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(paoxiao) or data.card.trueName ~= "slash" then return false end
    local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
      local use = e.data[1]
      return use.from == player.id and use.card.trueName == "slash"
    end, Player.HistoryTurn)
    return #events == 2 and events[2].id == player.room.logic:getCurrentEvent().id
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,

  refresh_events = {fk.CardUsing, fk.TargetSpecified, fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    if player ~= target then return false end -- 摆一下
    if event == fk.CardUsing then
      return player:hasSkill(paoxiao) and data.card.trueName == "slash" and player:usedCardTimes("slash") > 1
    else
      if event == fk.CardUseFinished then
        return (data.extra_data or {}).hsPaoxiaoNullifiled
      else
        local room = player.room
        return data.card.trueName == "slash" and player:hasSkill("hs__n_paoxiao") and H.getHegLord(room, player) and H.getHegLord(room, player):hasSkill("ld__n_shouyue") and room:getPlayerById(data.to):isAlive()
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      player:broadcastSkillInvoke("hs__n_paoxiao")
      room:doAnimate("InvokeSkill", {
        name = "paoxiao",
        player = player.id,
        skill_type = "offensive",
      })
    elseif event == fk.CardUseFinished then
      for key, num in pairs(data.extra_data.hsPaoxiaoNullifiled) do
        local p = room:getPlayerById(tonumber(key))
        if p:getMark(fk.MarkArmorNullified) > 0 then
          room:removePlayerMark(p, fk.MarkArmorNullified, num)
        end
      end
      data.hsPaoxiaoNullifiled = nil
    else
      room:addPlayerMark(room:getPlayerById(data.to), fk.MarkArmorNullified)
      data.extra_data = data.extra_data or {}
      data.extra_data.hsPaoxiaoNullifiled = data.extra_data.hsPaoxiaoNullifiled or {}
      data.extra_data.hsPaoxiaoNullifiled[tostring(data.to)] = (data.extra_data.hsPaoxiaoNullifiled[tostring(data.to)] or 0) + 1
    end
  end,
}
paoxiao:addRelatedSkill(paoxiaoTrigger)
zhangfei:addSkill(paoxiao)
Fk:loadTranslationTable{
  ["hs__n_zhangfei"] = "张飞",
  ["#hs__n_zhangfei"] = "万夫不当",

  ["hs__n_paoxiao"] = "咆哮",
  [":hs__n_paoxiao"] = "锁定技，你使用【杀】无次数限制。当你于每回合使用第二张【杀】时，你摸一张牌。",
  ["#hs__n_paoxiaoTrigger"] = "咆哮",

  ["$hs__n_paoxiao1"] = "啊~~~",
  ["$hs__n_paoxiao2"] = "燕人张飞在此！",
  ["~hs__n_zhangfei"] = "实在是杀不动了……",
}

-----
local zhugeliang = General(extension, "hs__n_zhugeliang", "shu", 3)
zhugeliang:addCompanions("hs__n_huangyueying")
local guanxing = fk.CreateTriggerSkill{
  name = "hs__n_guanxing",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = (H.inGeneralSkills(player, self.name) == "m" and player:hasShownSkill("ld__n_yizhi")) and 5 or math.min(5, #room.alive_players)
    room:askForGuanxing(player, room:getNCards(num))
  end,
}
local kongcheng = fk.CreateTriggerSkill{
  name = "hs__n_kongcheng",
  anim_type = "defensive",
  events = {fk.TargetConfirming, fk.BeforeCardsMove, fk.EventPhaseStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.EventPhaseStart then
      return player == target and player.phase == Player.Draw and #player:getPile("zither") > 0
    else
      if not player:isKongcheng() then return false end
      if event == fk.TargetConfirming then
        return target == player and (data.card.trueName == "slash" or data.card.name == "duel")
      elseif event == fk.BeforeCardsMove then
        if player.phase ~= Player.NotActive then return false end
        for _, move in ipairs(data) do
          if move.moveReason == fk.ReasonGive and move.to == player.id and move.toArea == Card.PlayerHand then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      AimGroup:cancelTarget(data, player.id)
      return true
    elseif event == fk.BeforeCardsMove then
      local mirror_moves = {}
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonGive and move.to == player.id and move.toArea == Card.PlayerHand then
          local mirror_info = move.moveInfo
          if #mirror_info > 0 then
            move.moveInfo = {}
            local mirror_move = table.clone(move)
            mirror_move.toArea = Card.PlayerSpecial
            mirror_move.specialName = "zither"
            mirror_move.visible = true
            mirror_move.moveMark = nil
            mirror_move.moveInfo = mirror_info
            table.insert(mirror_moves, mirror_move)
          end
        end
      end
      table.insertTable(data, mirror_moves)
    else
      room:obtainCard(player, player:getPile("zither"), true)
    end
  end
}
zhugeliang:addSkill(guanxing)
zhugeliang:addSkill(kongcheng)
Fk:loadTranslationTable{
  ["hs__n_zhugeliang"] = "诸葛亮",
  ["#hs__n_zhugeliang"] = "迟暮的丞相",
  ["illustrator:hs__n_zhugeliang"] = "木美人",

  ["hs__n_guanxing"] = "观星",
  [":hs__n_guanxing"] = "准备阶段，你可将牌堆顶的X张牌（X为角色数且至多为5）扣置入处理区（对你可见），你将其中任意数量的牌置于牌堆顶，将其余的牌置于牌堆底。",
  ["hs__n_kongcheng"] = "空城",
  [":hs__n_kongcheng"] = "锁定技，若你没有手牌：1. 当你成为【杀】或【决斗】的目标时，取消之；"..
    "2. 你的回合外，当牌因交给而移至你的手牌区前，你将此次移动的目标区域改为你的武将牌上（均称为“琴”），摸牌阶段开始时，你获得所有“琴”。",
  ["zither"] = "琴",

  ["$hs__n_guanxing1"] = "观今夜天象，知天下大事。",
  ["$hs__n_guanxing2"] = "知天易，逆天难。",
  ["$hs__n_kongcheng1"] = "（抚琴声）",
  ["$hs__n_kongcheng2"] = "（抚琴声）",
  ["~hs__n_zhugeliang"] = "将星陨落，天命难违。",
}

-----
local zhaoyun = General(extension, "hs__n_zhaoyun", "shu", 4)
zhaoyun:addCompanions("hs__n_liushan")
local longdan = fk.CreateViewAsSkill{
  name = "hs__n_longdan",
  pattern = "slash,jink",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    local _c = Fk:getCardById(to_select)
    local c
    if _c.trueName == "slash" then
      c = Fk:cloneCard("jink")
    elseif _c.name == "jink" then
      c = Fk:cloneCard("slash")
    else
      return false
    end
    return (Fk.currentResponsePattern == nil and Self:canUse(c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local _c = Fk:getCardById(cards[1])
    local c
    if _c.trueName == "slash" then
      c = Fk:cloneCard("jink")
    elseif _c.name == "jink" then
      c = Fk:cloneCard("slash")
    end
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}
local longdan_after = fk.CreateTriggerSkill{
  name = "#hs__n_longdan_after",
  anim_type = "offensive",
  visible = false,
  events = {fk.CardEffectCancelledOut, fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardEffectCancelledOut then
      if data.card.trueName ~= "slash" then return false end
      if target == player then -- 龙胆杀
        return table.contains(data.card.skillNames, "hs__n_longdan")
      elseif data.to == player.id then -- 龙胆闪
        for _, card in ipairs(data.cardsResponded) do
          if card.name == "jink" and table.contains(card.skillNames, "hs__n_longdan") then
            return true
          end
        end
      end
    else
      local room = player.room
      return player == target and H.getHegLord(room, player) and table.contains(data.card.skillNames, "hs__n_longdan") and H.getHegLord(room, player):hasSkill("ld__n_shouyue")
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardEffectCancelledOut then
      if target == player then
        local targets = table.map(room:getOtherPlayers(room:getPlayerById(data.to)), Util.IdMapper)
        if #targets == 0 then return false end
        local target = room:askForChoosePlayers(player, targets, 1, 1, "#longdan_slash-ask::" .. data.to, self.name, true)
        if #target > 0 then
          self.cost_data = target[1]
          return true
        end
        return false
      else
        local targets = table.map(table.filter(room:getOtherPlayers(target), function(p) return
          p ~= player and p:isWounded()
        end), Util.IdMapper)
        if #targets == 0 then return false end
        local target = room:askForChoosePlayers(player, targets, 1, 1, "#longdan_jink-ask::" .. target.id , self.name, true)
        if #target > 0 then
          self.cost_data = target[1]
          return true
        end
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    if event == fk.CardEffectCancelledOut then
      if target == player then
        room:damage{
          from = player,
          to = to,
          damage = 1,
          skillName = self.name,
        }
      else
        room:recover({
          who = to,
          num = 1,
          recoverBy = player,
          skillName = self.name,
        })
      end
    else
      player:drawCards(1, self.name)
    end
  end,
}
longdan:addRelatedSkill(longdan_after)
zhaoyun:addSkill(longdan)
Fk:loadTranslationTable{
  ["hs__n_zhaoyun"] = "赵云",
  ["#hs__n_zhaoyun"] = "虎威将军",
  ["illustrator:hs__n_zhaoyun"] = "DH",

  ["hs__n_longdan"] = "龙胆",
  [":hs__n_longdan"] = "①你可将【闪】当【杀】使用或打出，当此【杀】被一名角色使用的【闪】抵消后，你可对另一名角色造成1点伤害。②你可将【杀】当【闪】使用或打出，当一名角色使用的【杀】被此【闪】抵消后，你可令另一名其他角色回复1点体力。",
  ["#hs__n_longdan_after"] = "龙胆",
  ["#longdan_slash-ask"] = "龙胆：你可对 %dest 以外的一名角色造成1点伤害",
  ["#longdan_jink-ask"] = "龙胆：你可令 %dest 以外的一名其他角色回复1点体力",

  ["$hs__n_longdan1"] = "能进能退，乃真正法器！",
  ["$hs__n_longdan2"] = "吾乃常山赵子龙也！",
  ["~hs__n_zhaoyun"] = "这，就是失败的滋味吗？",
}

-----
local machao = General(extension, "hs__n_machao", "shu", 4)
local machao__mashu = fk.CreateDistanceSkill{
  name = "hs__n_machao__mashu",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      return -1
    end
  end,
}
local tieqi = fk.CreateTriggerSkill{
  name = "hs__n_tieqi",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|spade,club,heart,diamond",
    }
    if player.dead then return end
    local choices = {}
    if to.general ~= "anjiang" then
      table.insert(choices, to.general)
    end
    if to.deputyGeneral ~= "anjiang" then
      table.insert(choices, to.deputyGeneral)
    end
    local all_choices = {to.general, to.deputyGeneral}
    local disable_choices = table.filter(all_choices, function(g) return not table.contains(choices, g) end)
    if #choices > 0 then
      local choice
      if H.getHegLord(room, player) and #choices > 1 and H.getHegLord(room, player):hasSkill("ld__n_shouyue") then
        choice = choices
      else
        local result = room:askForCustomDialog(player, self.name,
        "packages/utility/qml/ChooseGeneralsAndChoiceBox.qml", {
          all_choices,
          {"OK"},
          "#hs__n_tieqi-ask::" .. to.id,
          {},
          1,
          1,
          disable_choices
        })
        if result ~= "" then
          local reply = json.decode(result)
          choice = reply.cards
        else
          choice = table.random(choices, 1)
        end
      end
      local record = to:getTableMark("@hs__n_tieqi-turn")
      for _, c in ipairs(choice) do
        table.insertIfNeed(record, c)
        room:setPlayerMark(to, "@hs__n_tieqi-turn", record)
        local mark = to:getTableMark("_hs__n_tieqi-turn")
        for _, skill_name in ipairs(Fk.generals[c]:getSkillNameList()) do
          if Fk.skills[skill_name].frequency ~= Skill.Compulsory then
            table.insertIfNeed(mark, skill_name)
          end
        end
        room:setPlayerMark(to, "_hs__n_tieqi-turn", mark)
      end
    end
    room:judge(judge)
    if judge.card.suit ~= nil then
      local suits = {}
      table.insert(suits, judge.card:getSuitString())
      if #room:askForDiscard(to, 1, 1, true, self.name, true, ".|.|" .. table.concat(suits, ","), "#hs__n_tieqi-discard:::" .. judge.card:getSuitString()) == 0 then
        data.disresponsive = true
      end
    end
  end,
}
local tieqiInvalidity = fk.CreateInvaliditySkill {
  name = "#hs__n_tieqi_invalidity",
  invalidity_func = function(self, from, skill)
    if from:getMark("_hs__n_tieqi-turn") ~= 0 then
      return table.contains(from:getMark("_hs__n_tieqi-turn"), skill.name) and
      (skill.frequency ~= Skill.Compulsory and skill.frequency ~= Skill.Wake) and not skill.name:endsWith("&")
    end
  end
}
tieqi:addRelatedSkill(tieqiInvalidity)
machao:addSkill(tieqi)
machao:addSkill(machao__mashu)
Fk:loadTranslationTable{
  ["hs__n_machao"] = "马超",
  ["#hs__n_machao"] = "一骑当千",
  ["illustrator:hs__n_machao"] = "KayaK&木美人&张帅",

  ["hs__n_tieqi"] = "铁骑",
  [":hs__n_tieqi"] = "当你使用【杀】指定目标后，你可判定，令其本回合一张明置的武将牌非锁定技失效，其需弃置一张与判定结果花色相同的牌，否则其不能使用【闪】抵消此【杀】。",
  ["hs__n_machao__mashu"] = "马术",
  [":hs__n_machao__mashu"] = "锁定技，你与其他角色的距离-1。",
  ["@hs__n_tieqi-turn"] = "铁骑",
  ["#hs__n_tieqi-ask"] = "铁骑：令 %dest 一张武将牌上的非锁定技此回合失效",
  ["#hs__n_tieqi-discard"] = "铁骑：你需弃置一张%arg牌，否则不能使用【闪】抵消此【杀】。",

  ["$hs__n_tieqi1"] = "目标敌阵，全军突击！",
  ["$hs__n_tieqi2"] = "敌人阵型已乱，随我杀！",
  ["~hs__n_machao"] = "请将我，葬在西凉……",
}

-----
local huangyueying = General(extension, "hs__n_huangyueying", "shu", 3, 3, General.Female)
huangyueying:addCompanions("hs__n_wolong")
local jizhi = fk.CreateTriggerSkill{
  name = "hs__n_jizhi",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card:isCommonTrick() and
      (not data.card:isVirtual() or #data.card.subcards == 0)
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}
local qicai = fk.CreateTargetModSkill{
  name = "hs__n_qicai",
  frequency = Skill.Compulsory,
  bypass_distances = function(self, player, skill, card)
    return player:hasSkill(self) and card and card.type == Card.TypeTrick
  end,
}
huangyueying:addSkill(jizhi)
huangyueying:addSkill(qicai)
Fk:loadTranslationTable{
  ["hs__n_huangyueying"] = "黄月英",
  ["#hs__n_huangyueying"] = "归隐的杰女",
  ["illustrator:hs__n_huangyueying"] = "木美人",

  ["hs__n_jizhi"] = "集智",
  [":hs__n_jizhi"] = "当你使用非转化的普通锦囊牌时，你可摸一张牌。",
  ["hs__n_qicai"] = "奇才",
  [":hs__n_qicai"] = "锁定技，你使用锦囊牌无距离限制。",

  ["$hs__n_jizhi1"] = "哼哼！",
  ["$hs__n_jizhi2"] = "哼~",
  ["~hs__n_huangyueying"] = "亮……",
}

-----
local huangzhong = General(extension, "hs__n_huangzhong", "shu", 4)
huangzhong:addCompanions("hs__n_weiyan")
local liegong = fk.CreateTriggerSkill{
  name = "hs__n_liegong",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self)) then return end
    local room = player.room
    local to = room:getPlayerById(data.to)
    local num = #to:getCardIds(Player.Hand)
    local filter = num <= player:getAttackRange() or num >= player.hp
    return data.card.trueName == "slash" and filter and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    data.disresponsiveList = data.disresponsiveList or {}
    table.insert(data.disresponsiveList, data.to)
  end,
}
local liegongAR = fk.CreateAttackRangeSkill{
  name = "#hs__n_liegongAR",
  correct_func = function(self, from, to)
    if from:hasSkill("hs__n_liegong") then
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        if string.find(p.general, "lord") and p:hasSkill("ld__n_shouyue") and p.kingdom == from.kingdom then
          return 1
        end
      end
    end
    return 0
  end,
}
liegong:addRelatedSkill(liegongAR)
huangzhong:addSkill(liegong)
Fk:loadTranslationTable{
  ["hs__n_huangzhong"] = "黄忠",
  ["#hs__n_huangzhong"] = "老当益壮",

  ["hs__n_liegong"] = "烈弓",
  [":hs__n_liegong"] = "当你于出牌阶段内使用【杀】指定目标后，若其手牌数不小于你的体力值或不大于你的攻击范围，你可令其不能使用【闪】响应此【杀】。",
  
  ["$hs__n_liegong1"] = "百步穿杨！",
  ["$hs__n_liegong2"] = "中！",
  ["~hs__n_huangzhong"] = "不得不服老了……",
}

-----
local weiyan = General(extension, "hs__n_weiyan", "shu", 4)
local kuanggu = fk.CreateTriggerSkill{
  name = "hs__n_kuanggu",
  anim_type = "drawcard",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and (data.extra_data or {}).kuanggucheck
  end,
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      self:doCost(event, target, player, data)
      if self.cost_data == "Cancel" then break end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local choices = {"draw1", "Cancel"}
    if player:isWounded() then
      table.insert(choices, 2, "recover")
    end
    self.cost_data = room:askForChoice(player, choices, self.name)
    return self.cost_data ~= "Cancel"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if self.cost_data == "recover" then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    elseif self.cost_data == "draw1" then
      player:drawCards(1, self.name)
    end
  end,

  refresh_events = {fk.BeforeHpChanged},
  can_refresh = function(self, event, target, player, data)
    return data.damageEvent and player == data.damageEvent.from and player:compareDistance(target, 2, "<")
  end,
  on_refresh = function(self, event, target, player, data)
    data.damageEvent.extra_data = data.damageEvent.extra_data or {}
    data.damageEvent.extra_data.kuanggucheck = true
  end,
}
weiyan:addSkill(kuanggu)
Fk:loadTranslationTable{
  ["hs__n_weiyan"] = "魏延",
  ["#hs__n_weiyan"] = "嗜血的独狼",
  ["illustrator:hs__n_weiyan"] = "瞌瞌一休",

  ["hs__n_kuanggu"] = "狂骨",
  [":hs__n_kuanggu"] = "当你对距离1以内的角色造成1点伤害后，你可摸一张牌或回复1点体力。",

  ["$hs__n_kuanggu1"] = "哈哈哈哈哈哈，赢你还不容易？",
  ["$hs__n_kuanggu2"] = "哼！也不看看我是何人！",
  ["~hs__n_weiyan"] = "奸贼……害我……",
}

-----
local pangtong = General(extension, "hs__n_pangtong", "shu", 3)
pangtong:addCompanions("hs__n_wolong")
local lianhuan = fk.CreateActiveSkill{
  name = "hs__n_lianhuan",
  mute = true,
  card_num = 1,
  min_target_num = 0,
  prompt = "#hs__n_lianhuan",
  can_use = function(self, player)
    return not player:isKongcheng()
  end,
  card_filter = function(self, to_select, selected, player)
    return #selected == 0 and Fk:getCardById(to_select).suit == Card.Club and table.contains(player:getHandlyIds(true), to_select)
  end,
  target_filter = function(self, to_select, selected, selected_cards, _, _, player)
    if #selected_cards == 1 then
      local card = Fk:cloneCard("iron_chain")
      card:addSubcard(selected_cards[1])
      card.skillName = self.name
      return player:canUse(card) and card.skill:targetFilter(to_select, selected, selected_cards, card, nil, player) and
      not player:prohibitUse(card) and not player:isProhibited(Fk:currentRoom():getPlayerById(to_select), card)
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:broadcastSkillInvoke(self.name)
    if #effect.tos == 0 then
      room:notifySkillInvoked(player, self.name, "drawcard")
      room:recastCard(effect.cards, player, self.name)
    else
      room:notifySkillInvoked(player, self.name, "control")
      room:sortPlayersByAction(effect.tos)
      room:useVirtualCard("iron_chain", effect.cards, player, table.map(effect.tos, function(id)
        return room:getPlayerById(id) end), self.name)
    end
  end,
}
local niepan = fk.CreateTriggerSkill{
  name = "hs__n_niepan",
  anim_type = "defensive",
  frequency = Skill.Limited,
  events = {fk.AskForPeaches},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.dying and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:throwAllCards("hej")
    if player.dead then return end
    player:reset()
    player:drawCards(3, self.name)
    if player.dead or not player:isWounded() then return end
    room:recover({
      who = player,
      num = math.min(3, player.maxHp) - player.hp,
      recoverBy = player,
      skillName = self.name,
    })
  end,
}
pangtong:addSkill(lianhuan)
pangtong:addSkill(niepan)
Fk:loadTranslationTable{
  ['hs__n_pangtong'] = '庞统',
  ["#hs__n_pangtong"] = "凤雏",
  ["illustrator:hs__n_pangtong"] = "KayaK",

  ["hs__n_lianhuan"] = "连环",
  [":hs__n_lianhuan"] = "你可以将一张♣手牌当【铁索连环】使用或重铸。",
  ["hs__n_niepan"] = "涅槃",
  [":hs__n_niepan"] = "限定技，当你处于濒死状态时，你可以弃置区域里的所有牌，复原你的武将牌，然后摸三张牌并将体力回复至3点。",
  ["#hs__n_lianhuan"] = "连环：你可以将一张♣手牌当【铁索连环】使用或重铸",

  ["$hs__n_lianhuan1"] = "伤一敌可连其百！",
  ["$hs__n_lianhuan2"] = "通通连起来吧！",
  ["$hs__n_niepan1"] = "凤雏岂能消亡？",
  ["$hs__n_niepan2"] = "浴火重生！",
  ["~hs__n_pangtong"] = "看来我命中注定将丧命于此……",
}

-----
local wolong = General(extension, "hs__n_wolong", "shu", 3)
local bazhen = fk.CreateTriggerSkill{
  name = "hs__n_bazhen",
  events = {fk.AskForCardUse, fk.AskForCardResponse},
  frequency = Skill.Compulsory,
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isFakeSkill(self) and
      (data.cardName == "jink" or (data.pattern and Exppattern:Parse(data.pattern):matchExp("jink|0|nosuit|none"))) and
      not player:getEquipment(Card.SubtypeArmor)
      and Fk.skills["#eight_diagram_skill"] ~= nil and Fk.skills["#eight_diagram_skill"]:isEffectable(player)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, data)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judgeData = {
      who = player,
      reason = "eight_diagram",
      pattern = ".|.|heart,diamond",
    }
    room:judge(judgeData)
    if judgeData.card.color == Card.Red then
      local card = Fk:cloneCard("jink")
      card.skillName = "eight_diagram"
      card.skillName = "bazhen"
      if event == fk.AskForCardUse then
        if player:prohibitUse(card) then return false end
        data.result = {
          from = player.id,
          card = card,
        }
        if data.eventData then
          data.result.toCard = data.eventData.toCard
          data.result.responseToEvent = data.eventData.responseToEvent
        end
      else
        if player:prohibitResponse(card) then return false end
        data.result = card
      end
      return true
    end
  end
}
local huoji = fk.CreateViewAsSkill{
  name = "hs__n_huoji",
  anim_type = "offensive",
  pattern = "fire_attack",
  prompt = "#hs__n_huoji",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Red and table.contains(Self:getHandlyIds(true), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("fire_attack")
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
}
local kanpo = fk.CreateViewAsSkill{
  name = "hs__n_kanpo",
  anim_type = "control",
  pattern = "nullification",
  prompt = "#hs__n_kanpo",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black and table.contains(Self:getHandlyIds(true), to_select)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("nullification")
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
  enabled_at_response = function (self, player, response)
    return not response and not player:isKongcheng()
  end,
}
wolong:addSkill(bazhen)
wolong:addSkill(huoji)
wolong:addSkill(kanpo)
Fk:loadTranslationTable{
  ['hs__n_wolong'] = '卧龙诸葛亮',
  ["#hs__n_wolong"] = "卧龙",
  ["illustrator:hs__n_wolong"] = "绘聚艺堂",

  ["hs__n_bazhen"] = "八阵",
  [":hs__n_bazhen"] = "锁定技，若你没有装备防具，视为你装备着【八卦阵】。",
  ["hs__n_huoji"] = "火计",
  [":hs__n_huoji"] = "你可以将一张红色手牌当【火攻】使用。",
  ["hs__n_kanpo"] = "看破",
  [":hs__n_kanpo"] = "你可以将一张黑色手牌当【无懈可击】使用。",
  ["#hs__n_huoji"] = "火计：你可以将一张红色手牌当【火攻】使用",
  ["#hs__n_kanpo"] = "看破：你可以将一张黑色手牌当【无懈可击】使用",

  ["$hs__n_bazhen1"] = "你可识得此阵？",
  ["$hs__n_bazhen2"] = "太极生两仪，两仪生四象，四象生八卦。",
  ["$hs__n_huoji1"] = "此火可助我军大获全胜。",
  ["$hs__n_huoji2"] = "燃烧吧！",
  ["$hs__n_kanpo1"] = "雕虫小技。",
  ["$hs__n_kanpo2"] = "你的计谋被识破了。",
  ["~hs__n_wolong"] = "我的计谋竟被……",
}

-----
local liushan = General(extension, "hs__n_liushan", "shu", 3)
local xiangle = fk.CreateTriggerSkill{
  name = "hs__n_xiangle",
  events = {fk.TargetConfirmed},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #room:askForDiscard(room:getPlayerById(data.from), 1, 1, false, self.name, true, ".|.|.|.|.|basic", "#hs__n_xiangle-discard:"..player.id) == 0 then
      table.insertIfNeed(data.nullifiedTargets, player.id)
    end
  end,
}
local fangquan = fk.CreateTriggerSkill{
  name = "hs__n_fangquan",
  anim_type = "support",
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.to == Player.Play
  end,
  on_use = Util.TrueFunc,
}
local fangquan_delay = fk.CreateTriggerSkill{
  name = "#hs__n_fangquan_delay",
  events = {fk.TurnEnd},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:usedSkillTimes(fangquan.name, Player.HistoryTurn) > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, fangquan.name, "support")
    local tar, card =  room:askForChooseCardAndPlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, ".|.|.|hand", "#hs__n_fangquan-choose", fangquan.name, true)
    if #tar > 0 and card then
      room:throwCard(card, fangquan.name, player, player)
      room:getPlayerById(tar[1]):gainAnExtraTurn()
    end
  end,
}
fangquan:addRelatedSkill(fangquan_delay)
liushan:addSkill(xiangle)
liushan:addSkill(fangquan)
Fk:loadTranslationTable{
  ['hs__n_liushan'] = '刘禅',
  ["#hs__n_liushan"] = "无为的真命主",
  ["illustrator:hs__n_liushan"] = "LiuHeng",

  ["hs__n_xiangle"] = "享乐",
  [":hs__n_xiangle"] = "锁定技，当你成为【杀】的目标后，你令使用者选择：1. 弃置一张基本牌；2. 此【杀】对你无效。",
  ["hs__n_fangquan"] = "放权",
  [":hs__n_fangquan"] = "你可以跳过你的出牌阶段，然后此回合结束时，你可以弃置一张手牌并选择一名其他角色，然后其获得一个额外回合。",
  ["#hs__n_xiangle-discard"] = "享乐：你须弃置一张基本牌，否则此【杀】对 %src 无效",
  ["#hs__n_fangquan_delay"] = "放权",
  ["#hs__n_fangquan-choose"] = "放权：弃置一张手牌，令一名角色获得一个额外回合",

  ["$hs__n_xiangle1"] = "打打杀杀，真没意思。",
  ["$hs__n_xiangle2"] = "我爸爸是刘备！",
  ["$hs__n_fangquan1"] = "唉，这可如何是好啊！",
  ["$hs__n_fangquan2"] = "哎，你办事儿，我放心~",
  ["~hs__n_liushan"] = "别打脸，我投降还不行吗？",
}

-----
local menghuo = General(extension, "hs__n_menghuo", "shu", 4)
menghuo:addCompanions("hs__n_zhurong")
local huoshou = fk.CreateTriggerSkill{
  name = "hs__n_huoshou",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.card.trueName == "savage_assault" then
      if event == fk.PreCardEffect then
        return player.id == data.to
      else
        return target ~= player and data.firstTarget
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      return true
    else
      data.extra_data = data.extra_data or {}
      data.extra_data.huoshou = player.id
    end
  end,

  refresh_events = {fk.PreDamage},
  can_refresh = function(self, event, target, player, data)
    if data.card and data.card.trueName == "savage_assault" then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      if e then
        local use = e.data[1]
        return use.extra_data and use.extra_data.huoshou
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local e = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
    if e then
      local use = e.data[1]
      data.from = room:getPlayerById(use.extra_data.huoshou)
    end
  end,
}
local zaiqi = fk.CreateTriggerSkill{
  name = "hs__n_zaiqi",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw and player:isWounded()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getLostHp()
    local cards = room:getNCards(n)
    room:moveCards{
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonJustMove,
      skillName = self.name,
      proposer = player.id,
    }
    room:delay(2000)
    local hearts, to_get = {}, {}
    for _, id in ipairs(cards) do
      if Fk:getCardById(id).suit == Card.Heart then
        table.insert(hearts, id)
      else
        table.insert(to_get, id)
      end
    end
    if #hearts > 0 then
      if player:isWounded() then
        room:recover({
          who = player,
          num = math.min(#hearts, player:getLostHp()),
          recoverBy = player,
          skillName = self.name,
        })
      end
      room:moveCards{
        ids = hearts,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
        skillName = self.name,
      }
    end
    if #to_get > 0 and not player.dead then
      room:obtainCard(player.id, to_get, true, fk.ReasonJustMove)
    end
    cards = table.filter(cards, function (id)
      return room:getCardArea(id) == Card.Processing
    end)
    if #cards > 0 then
      room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonJustMove, self.name)
    end
    return true
  end,
}
menghuo:addSkill(huoshou)
menghuo:addSkill(zaiqi)
Fk:loadTranslationTable{
  ['hs__n_menghuo'] = '孟获',
  ["#hs__n_menghuo"] = "南蛮王",
  ["illustrator:hs__n_menghuo"] = "废柴男",

  ["hs__n_huoshou"] = "祸首",
  [":hs__n_huoshou"] = "锁定技，【南蛮入侵】对你无效；当其他角色使用【南蛮入侵】指定目标后，你代替其成为此牌造成的伤害的来源。",
  ["hs__n_zaiqi"] = "再起",
  [":hs__n_zaiqi"] = "摸牌阶段，若你已受伤，你可以放弃摸牌，改为亮出牌堆顶X张牌（X为你已损失体力值），你将其中的<font color='red'>♥</font>牌置入弃牌堆"..
  "并回复等量体力，获得其余的牌。",

  ["$hs__n_huoshou1"] = "背黑锅我来，送死？你去！",
  ["$hs__n_huoshou2"] = "通通算我的！",
  ["$hs__n_zaiqi1"] = "丞相助我！",
  ["$hs__n_zaiqi2"] = "起！",
  ["~hs__n_menghuo"] = "七纵之恩……来世……再报了……",
}

-----
local zhurong = General(extension, "hs__n_zhurong", "shu", 4, 4, General.Female)
local juxiang = fk.CreateTriggerSkill{
  name = "hs__n_juxiang",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if not (player:hasSkill(self) and data.card and data.card.trueName == "savage_assault") then return end
    if event == fk.PreCardEffect then
      return data.to == player.id
    else
      return target ~= player and U.hasFullRealCard(player.room, data.card)
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.PreCardEffect then
      return true
    else
      player.room:obtainCard(player, data.card, true, fk.ReasonJustMove)
    end
  end,
}
local lieren = fk.CreateTriggerSkill{
  name = "hs__n_lieren",
  anim_type = "offensive",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" and
      not data.to.dead and player:canPindian(data.to) and not data.chain
      and player.room.logic:damageByCardEffect()
  end,
  on_cost = function (self, event, target, player, data)
    self.cost_data = {tos = {data.to.id}}
    return player.room:askForSkillInvoke(player, self.name, nil, "#hs__n_lieren-invoke:"..data.to.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local pindian = player:pindian({data.to}, self.name)
    if pindian.results[data.to.id].winner == player and not data.to:isNude() then
      local card = room:askForCardChosen(player, data.to, "he", self.name)
      room:obtainCard(player, card, false, fk.ReasonPrey)
    end
  end,
}
zhurong:addSkill(juxiang)
zhurong:addSkill(lieren)
Fk:loadTranslationTable{
  ['hs__n_zhurong'] = '祝融',
  ["#hs__n_zhurong"] = "野性的女王",
  ["illustrator:hs__n_zhurong"] = "废柴男",

  ["hs__n_juxiang"] = "巨象",
  [":hs__n_juxiang"] = "锁定技，【南蛮入侵】对你无效；其他角色使用的【南蛮入侵】结算结束后，你获得之。",
  ["hs__n_lieren"] = "烈刃",
  [":hs__n_lieren"] = "当你使用【杀】对一个目标造成伤害后，你可以与其拼点，若你赢，你获得其一张牌。",
  ["#hs__n_lieren-invoke"] = "烈刃：你可以与 %src 拼点，若你赢，你获得其一张牌。",

  ["$hs__n_juxiang1"] = "大王，看我的。",
  ["$hs__n_juxiang2"] = "小小把戏~",
  ["$hs__n_lieren1"] = "亮兵器吧。",
  ["$hs__n_lieren2"] = "尝尝我飞刀的厉害！",
  ["~hs__n_zhurong"] = "大王，我，先走一步了。",
}

-----
local ganfuren = General(extension, "hs__n_ganfuren", "shu", 3, 3, General.Female)
local shushen = fk.CreateTriggerSkill{
  name = "hs__n_shushen",
  anim_type = "support",
  events = {fk.HpRecover},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.num do
      if self.cancel_cost then break end
      self:doCost(event, target, player, data)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player, false),
    Util.IdMapper), 1, 1, "#hs__n_shushen-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    if not to:isKongcheng() then
      to:drawCards(1, self.name)
    else
      to:drawCards(2, self.name)
    end
  end,
}
local shenzhi = fk.CreateTriggerSkill{
  name = "hs__n_shenzhi",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and
    table.find(player:getCardIds("h"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(player:getCardIds("h"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
    room:throwCard(cards, self.name, player, player)
    if player:isWounded() and not player.dead and #cards >= player.hp then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}
ganfuren:addSkill(shushen)
ganfuren:addSkill(shenzhi)
Fk:loadTranslationTable{
  ['hs__n_ganfuren'] = '甘夫人',
  ["#hs__n_ganfuren"] = "昭烈皇后",
  ["illustrator:hs__n_ganfuren"] = "琛·美弟奇",
  ["designer:hs__n_ganfuren"] = "淬毒",

  ["hs__n_shushen"] = "淑慎",
  [":hs__n_shushen"] = "当你回复1点体力后，你可令一名其他角色摸一张牌，若其没有手牌，则改为摸两张牌。",
  ["hs__n_shenzhi"] = "神智",
  [":hs__n_shenzhi"] = "准备阶段开始时，你可以弃置所有手牌，若你以此法弃置的手牌数不小于X，你回复1点体力(X为你当前的体力值)。",
  ["#hs__n_shushen-choose"] = "淑慎：你可令一名其他角色摸一张牌",

  ["$hs__n_shushen1"] = "船到桥头自然直。",
  ["$hs__n_shushen2"] = "妾身无恙，相公请安心征战。",
  ["$hs__n_shenzhi1"] = "子龙将军，一切都托付给你了。",
  ["$hs__n_shenzhi2"] = "阿斗，相信妈妈，没事的。",
  ["~hs__n_ganfuren"] = "请替我照顾好阿斗……",
}

-----
local sunquan = General(extension, "hs__n_sunquan", "wu", 4)
sunquan:addCompanions("hs__n_zhoutai")
local zhiheng = fk.CreateActiveSkill{
  name = "hs__n_zhiheng",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_num = 0,
  min_card_num = 1,
  max_card_num = function()
    return table.find(Self:getEquipments(Card.SubtypeTreasure), function(cid)
      return Fk:getCardById(cid).name == "luminous_pearl"
    end) and 998 or Self.maxHp
  end,
  card_filter = function(self, to_select, selected)
    if #selected >= Self.maxHp then
      return table.find(Self:getEquipments(Card.SubtypeTreasure), function(cid)
        return Fk:getCardById(cid).name == "luminous_pearl" and not table.contains(selected, cid) and to_select ~= cid
      end)
    end
    return #selected < Self.maxHp and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, from, from)
    if not from.dead then
      from:drawCards(#effect.cards, self.name)
    end
  end
}
sunquan:addSkill(zhiheng)
Fk:loadTranslationTable{
  ["hs__n_sunquan"] = "孙权",
  ["#hs__n_sunquan"] = "年轻的贤君",
  ["illustrator:hs__n_sunquan"] = "KayaK",

  ["hs__n_zhiheng"] = "制衡",
  [":hs__n_zhiheng"] = "出牌阶段限一次，你可弃置至多X张牌（X为你的体力上限），然后你摸等量的牌。",

  ["$hs__n_zhiheng1"] = "容我三思。",
  ["$hs__n_zhiheng2"] = "且慢。",
  ["~hs__n_sunquan"] = "父亲，大哥，仲谋愧矣……",
}

local ganning = General(extension, "hs__n_ganning", "wu", 4)
local qixi = fk.CreateViewAsSkill{
  name = "hs__n_qixi",
  anim_type = "control",
  pattern = "dismantlement",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("dismantlement")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end
}
ganning:addSkill(qixi)
Fk:loadTranslationTable{
  ["hs__n_ganning"] = "甘宁",
  ["#hs__n_ganning"] = "锦帆游侠",
  ["illustrator:hs__n_ganning"] = "KayaK",

  ["hs__n_qixi"] = "奇袭",
  [":hs__n_qixi"] = "你可以将一张黑色牌当【过河拆桥】使用。",
  
  ["$hs__n_qixi1"] = "接招吧。",
  ["$hs__n_qixi2"] = "你的牌太多了！",
  ["~hs__n_ganning"] = "二十年后，又是一条好汉！",
}

local lvmeng = General(extension, "hs__n_lvmeng", "wu", 4)
local keji = fk.CreateTriggerSkill{
  name = "hs__n_keji",
  anim_type = "defensive",
  events = {fk.EventPhaseStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) or player.phase ~= Player.Discard then return false end 
    local cards, play_ids = {}, {}
    local logic = player.room.logic
    logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
      if e.data[2] == Player.Play then
        table.insert(play_ids, {e.id, e.end_id})
      end
      return false
    end, Player.HistoryTurn)
    logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
      local in_play = false
      for _, ids in ipairs(play_ids) do
        if #ids == 2 and e.id > ids[1] and e.id < ids[2] then
          in_play = true
          break
        end
      end
      if in_play then
        local use = e.data[1]
        if use.from == player.id and (use.card.color ~= Card.NoColor) then
          table.insertIfNeed(cards, use.card.color)
        end
      end
    end, Player.HistoryTurn)
    return #cards <= 1
  end,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn, 4)
  end
}
local mouduan = fk.CreateTriggerSkill{
  name = "hs__n_mouduan",
  events = {fk.EventPhaseStart},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target ~= player or not player:hasSkill(self) or player.phase ~= Player.Finish then return false end 
    local suits, types, play_ids = {}, {}, {}
    local logic = player.room.logic
    logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
      if e.data[2] == Player.Play then
        table.insert(play_ids, {e.id, e.end_id})
      end
      return false
    end, Player.HistoryTurn)
    logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
      local in_play = false
      for _, ids in ipairs(play_ids) do
        if #ids == 2 and e.id > ids[1] and e.id < ids[2] then
          in_play = true
          break
        end
      end
      if in_play then
        local use = e.data[1]
        if use.from == player.id then
          table.insertIfNeed(suits, use.card.suit)
          table.insertIfNeed(types, use.card.type)
        end
      end
    end, Player.HistoryTurn)
    return #suits >= 4 or #types >= 3
  end,
  on_cost = function(self, event, target, player, data)
    local targets = player.room:askForChooseToMoveCardInBoard(player, "#hs__n_mouduan-move", self.name, true, nil)
    if #targets ~= 0 then
      self.cost_data = targets
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local targets = self.cost_data
    local room = player.room
    targets = table.map(targets, function(id) return room:getPlayerById(id) end)
    room:askForMoveCardInBoard(player, targets[1], targets[2], self.name)
  end
}
lvmeng:addSkill(keji)
lvmeng:addSkill(mouduan)
Fk:loadTranslationTable{
  ["hs__n_lvmeng"] = "吕蒙",
  ["#hs__n_lvmeng"] = "白衣渡江",
  ["illustrator:hs__n_lvmeng"] = "樱花闪乱",

  ["hs__n_keji"] = "克己",
  [":hs__n_keji"] = "锁定技，弃牌阶段开始时，若你于出牌阶段内未使用过有颜色的牌，或于出牌阶段内使用过的所有的牌的颜色均相同，你的手牌上限于此回合内+4。",
  ["hs__n_mouduan"] = "谋断",
  [":hs__n_mouduan"] = "结束阶段，若你于出牌阶段内使用过四种花色或三种类别的牌，你可移动场上的一张牌。",
  ["#hs__n_mouduan-move"] = "谋断：你可选择两名角色，移动他们场上的一张牌",

  ["$hs__n_keji1"] = "谨慎为妙。",
  ["$hs__n_keji2"] = "时机未到。",
  ["$hs__n_mouduan1"] = "今日起兵，渡江攻敌！",
  ["$hs__n_mouduan2"] = "时机已到，全军出击！。",
  ["~hs__n_lvmeng"] = "种下恶因，必有恶果。",
}

-----
local huanggai = General(extension, "hs__n_huanggai", "wu", 4)
huanggai:addCompanions("hs__n_zhouyu")
local kurou = fk.CreateActiveSkill{
  name = "hs__n_kurou",
  anim_type = "drawcard",
  card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, from, from)
    if from.dead then return end
    room:loseHp(from, 1, self.name)
    if from.dead then return end
    from:drawCards(3, self.name)
  end
}
local kurouBuff = fk.CreateTargetModSkill{
  name = "#hs__n_kurou_buff",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      return player:usedSkillTimes("hs__n_kurou", Player.HistoryPhase)
    end
  end,
}
kurou:addRelatedSkill(kurouBuff)
huanggai:addSkill(kurou)
Fk:loadTranslationTable{
  ["hs__n_huanggai"] = "黄盖",
  ["#hs__n_huanggai"] = "轻身为国",
  ["illustrator:hs__n_huanggai"] = "G.G.G.",

  ["hs__n_kurou"] = "苦肉",
  [":hs__n_kurou"] = "出牌阶段限一次，你可弃置一张牌，然后你失去1点体力，摸三张牌，于此阶段内使用【杀】的次数上限+1。",

  ["$hs__n_kurou1"] = "我这把老骨头，不算什么！",
  ["$hs__n_kurou2"] = "为成大业，死不足惜！",
  ["~hs__n_huanggai"] = "盖，有负公瑾重托……",
}

-----
local zhouyu = General(extension, "hs__n_zhouyu", "wu", 3)
zhouyu:addCompanions("hs__n_xiaoqiao")
local yingzi = fk.CreateTriggerSkill{
  name = "hs__n_yingzi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  on_use = function(self, event, target, player, data)
    data.n = data.n + 1
  end,
}
local yingzi_maxcards = fk.CreateMaxCardsSkill{
  name = "#hs__n_yingzi_maxcards",
  main_skill = yingzi,
  fixed_func = function(self, player)
    if player:hasShownSkill(yingzi) then
      return player.maxHp
    end
  end
}
local fanjian = fk.CreateActiveSkill{
  name = "hs__n_fanjian",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "#hs__n_fanjian",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local cid = effect.cards[1]
    local player = room:getPlayerById(effect.from)
    player:showCards(cid)
    if player.dead then return end
    local suit = Fk:getCardById(cid).suit
    local suitString = Fk:getCardById(cid):getSuitString(true)
    local target = room:getPlayerById(effect.tos[1])
    room:obtainCard(target.id, cid, true, fk.ReasonGive)
    if target.dead then return end
    local choices = { "hs__n_fanjian_show:::" .. suitString, "loseHp" }
    if target.hp <= 0 then table.remove(choices) end
    if (target:isKongcheng() and table.every(target:getCardIds(Player.Equip), function (id)
      return Fk:getCardById(id).suit ~= suit
    end)) or suit == Card.NoSuit then table.remove(choices, 1) end
    if #choices == 0 then return end
    local choice = room:askForChoice(target, choices, self.name)
    if choice == "loseHp" then
      room:loseHp(target, 1, self.name)
    else
      local cards = target:getCardIds(Player.Hand)
      target:showCards(cards)
      room:delay(500)
      if target.dead then return end
      local discards = table.filter(target:getCardIds{ Player.Hand, Player.Equip }, function(id)
        return Fk:getCardById(id).suit == suit and not target:prohibitDiscard(Fk:getCardById(id))
      end)
      room:throwCard(discards, self.name, target, target)
    end
  end,
}
yingzi:addRelatedSkill(yingzi_maxcards)
zhouyu:addSkill(yingzi)
zhouyu:addSkill(fanjian)
Fk:loadTranslationTable{
  ["hs__n_zhouyu"] = "周瑜",
  ["#hs__n_zhouyu"] = "大都督",
  ["illustrator:hs__n_zhouyu"] = "绘聚艺堂",

  ["hs__n_yingzi"] = "英姿",
  [":hs__n_yingzi"] = "锁定技，摸牌阶段，你多摸一张牌；你的手牌上限等同于你的体力上限。",
  ["hs__n_fanjian"] = "反间",
  [":hs__n_fanjian"] = "出牌阶段限一次，你可以展示一张手牌并交给一名其他角色，然后其选择：1.展示所有手牌，弃置所有与你以展示的牌花色相同的牌；"..
  "2.失去1点体力。",
  ["#hs__n_fanjian"] = "反间：展示一张手牌并交给一名角色，其选择弃置所有此花色牌或失去1点体力",
  ["hs__n_fanjian_show"] = "展示手牌，弃置你所有的%arg牌",

  ["$hs__n_yingzi1"] = "哈哈哈哈哈哈哈哈！",
  ["$hs__n_yingzi2"] = "伯符，且看我这一手！",
  ["$hs__n_fanjian1"] = "与我为敌，就当这般生不如死！",
  ["$hs__n_fanjian2"] = "抉择吧！在苦与痛的地狱中！",
  ["~hs__n_zhouyu"] = "既生瑜，何生亮。既生瑜，何生亮！",
}

-----
local daqiao = General(extension, "hs__n_daqiao", "wu", 3, 3, General.Female)
daqiao:addCompanions("hs__n_xiaoqiao")
local guose = fk.CreateViewAsSkill{
  name = "hs__n_guose",
  anim_type = "control",
  pattern = "indulgence",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).suit == Card.Diamond
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("indulgence")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end
}
local liuli = fk.CreateTriggerSkill{
  name = "hs__n_liuli",
  anim_type = "defensive",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    local ret = target == player and player:hasSkill(self) and
      data.card.trueName == "slash"
    if ret then
      local room = player.room
      local from = room:getPlayerById(data.from)
      for _, p in ipairs(room.alive_players) do
        if p ~= player and p.id ~= data.from and player:inMyAttackRange(p) and not from:isProhibited(p, data.card) then
          return true
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#hs__n_liuli-target"
    local targets = {}
    local from = room:getPlayerById(data.from)
    for _, p in ipairs(room.alive_players) do
      if p ~= player and p.id ~= data.from and player:inMyAttackRange(p) and not from:isProhibited(p, data.card) then
        table.insert(targets, p.id)
      end
    end
    if #targets == 0 then return false end
    local plist, cid = room:askForChooseCardAndPlayers(player, targets, 1, 1, nil, prompt, self.name, true)
    if #plist > 0 then
      self.cost_data = {plist[1], cid}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = self.cost_data[1]
    room:doIndicate(player.id, { to })
    room:throwCard(self.cost_data[2], self.name, player, player)
    AimGroup:cancelTarget(data, player.id)
    AimGroup:addTargets(room, data, to)
  end,
}
daqiao:addSkill(guose)
daqiao:addSkill(liuli)
Fk:loadTranslationTable{
  ["hs__n_daqiao"] = "大乔",
  ["#hs__n_daqiao"] = "矜持之花",
  ["illustrator:hs__n_daqiao"] = "KayaK",

  ["hs__n_guose"] = "国色",
  [":hs__n_guose"] = "你可以将一张方块牌当【乐不思蜀】使用。",
  ["hs__n_liuli"] = "流离",
  [":hs__n_liuli"] = "当你成为【杀】的目标时，你可以弃置一张牌并选择你攻击范围内为此【杀】合法目标（无距离限制）的一名角色：若如此做，该角色代替你成为此【杀】的目标。",

  ["$hs__n_guose1"] = "旅途劳顿，请下马休整吧~",
  ["$hs__n_guose2"] = "还没到休息的时候！",
  ["$hs__n_liuli1"] = "帮帮人家嘛~",
  ["$hs__n_liuli2"] = "伯符不在身边，我要自己保重！",
  ["~hs__n_daqiao"] = "伯符，我去了……",
}

-----
local luxun = General(extension, "hs__n_luxun", "wu", 3)
local qianxun = fk.CreateTriggerSkill{
  name = "hs__n_qianxun",
  anim_type = "defensive",
  events = {fk.TargetConfirming, fk.BeforeCardsMove},
  frequency = Skill.Compulsory,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.TargetConfirming then
      return target == player and player:hasSkill(self) and data.card.name == "snatch"
    elseif event == fk.BeforeCardsMove then
      local id = 0
      local source = player
      local room = player.room
      local c
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerJudge then
          for _, info in ipairs(move.moveInfo) do
            id = info.cardId
            if info.fromArea == Card.PlayerJudge then
              source = room:getPlayerById(move.from) or player
            else
              source = player
            end
            c = source:getVirualEquip(id)
            --FIXME：巨大隐患，延时锦囊的virtual_equips在置入判定区的事件被篡改，或者判定阶段自然流程以外的方式离开判定区时不会清理
            if not c then c = Fk:getCardById(id) end
            if c.trueName == "indulgence" then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name)
    if event == fk.TargetConfirming then
      player:broadcastSkillInvoke(self.name, 2)
      AimGroup:cancelTarget(data, player.id)
      return true
    elseif event == fk.BeforeCardsMove then
      player:broadcastSkillInvoke(self.name, 1)
      local source = player
      local mirror_moves = {}
      local ids = {}
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerJudge then
          local move_info = {}
          local mirror_info = {}
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if info.fromArea == Card.PlayerJudge then
              source = room:getPlayerById(move.from) or player
            else
              source = player
            end
            local c = source:getVirualEquip(id)
            if not c then c = Fk:getCardById(id) end
            if c.trueName == "indulgence" then
              table.insert(mirror_info, info)
              table.insert(ids, id)
            else
              table.insert(move_info, info)
            end
          end
          if #mirror_info > 0 then
            move.moveInfo = move_info
            local mirror_move = table.clone(move)
            mirror_move.to = nil
            mirror_move.toArea = Card.DiscardPile
            mirror_move.moveInfo = mirror_info
            table.insert(mirror_moves, mirror_move)
          end
        end
      end
      table.insertTable(data, mirror_moves)
    end
  end
}
local duoshi = fk.CreateTriggerSkill{
  name = "hs__n_duoshi",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    local card = Fk:cloneCard("await_exhausted")
    return player:hasSkill(self) and player == target and player.phase == Player.Play and not player:prohibitUse(card)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p) return
      H.compareKingdomWith(p, player) end)
    room:useVirtualCard("await_exhausted", {}, player, targets, self.name)
  end,
}
luxun:addSkill(qianxun)
luxun:addSkill(duoshi)
Fk:loadTranslationTable{
  ["hs__n_luxun"] = "陆逊",
  ["#hs__n_luxun"] = "擎天之柱",
  ["illustrator:hs__n_luxun"] = "KayaK",

  ["hs__n_qianxun"] = "谦逊",
  [":hs__n_qianxun"] = "锁定技，当你成为【顺手牵羊】或【乐不思蜀】的目标时，你取消此目标。",
  ["hs__n_duoshi"] = "度势",
  [":hs__n_duoshi"] = "出牌阶段开始时，你可以视为使用一张【以逸待劳】。",

  ["$hs__n_qianxun1"] = "儒生脱尘，不为贪逸淫乐之事。",
  ["$hs__n_qianxun2"] = "谦谦君子，不饮盗泉之水。",
  ["$hs__n_duoshi1"] = "以今日之大势，当行此计。",
  ["$hs__n_duoshi2"] = "国之大计，审势为先。",
  ["~hs__n_luxun"] = "还以为我已经不再年轻……",
}

-----
local sunshangxiang = General(extension, "hs__n_sunshangxiang", "wu", 3, 3, General.Female)
local xiaoji = fk.CreateTriggerSkill{
  name = "hs__n_xiaoji",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    if player.room.current == player then
      player:drawCards(1, self.name)
    else
      player:drawCards(3, self.name)
    end
  end,
}
local jieyin = fk.CreateActiveSkill{
  name = "hs__n_jieyin",
  prompt = "#hs__n_jieyin-active",
  anim_type = "support",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected < 2 and Fk:currentRoom():getCardArea(to_select) == Player.Hand and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return target:isWounded() and target:isMale() and #selected < 1 and to_select ~= Self.id
  end,
  target_num = 1,
  card_num = 2,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:throwCard(effect.cards, self.name, from, from)
    if target:isAlive() and target:isWounded() then
      room:recover({
        who = room:getPlayerById(effect.tos[1]),
        num = 1,
        recoverBy = from,
        skillName = self.name
      })
    end
    if from:isAlive() and from:isWounded() then
      room:recover({
        who = from,
        num = 1,
        recoverBy = from,
        skillName = self.name
      })
    end
  end
}
sunshangxiang:addSkill(jieyin)
sunshangxiang:addSkill(xiaoji)
Fk:loadTranslationTable{
  ["hs__n_sunshangxiang"] = "孙尚香",
  ["#hs__n_sunshangxiang"] = "弓腰姬",
  ["illustrator:hs__n_sunshangxiang"] = "凡果",

  ["hs__n_xiaoji"] = "枭姬",
  [":hs__n_xiaoji"] = "当你失去装备区的装备牌后，若此时是你的回合内，你摸一张牌，否则你摸三张牌。",
  ["hs__n_jieyin"] = "结姻",
  [":hs__n_jieyin"] = "出牌阶段限一次，你可弃置两张手牌并选择一名已受伤的其他男性角色，你与其各回复1点体力。",
  ["#hs__n_jieyin-active"] = "结姻：你可以弃置两张手牌并选择一名其他男性角色，你与其各回复1点体力",

  ["$hs__n_jieyin1"] = "夫君，身体要紧。",
  ["$hs__n_jieyin2"] = "他好，我也好。",
  ["$hs__n_xiaoji1"] = "哼！",
  ["$hs__n_xiaoji2"] = "看我的厉害！",
  ["~hs__n_sunshangxiang"] = "不！还不可以死！",
}

-----
local sunjian = General:new(extension, "hs__n_sunjian", "wu", 5)
local yinghun = fk.CreateTriggerSkill{
  name = "hs__n_yinghun",
  anim_type = "drawcard",
  mute = true,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player, false), function (p)
      return p.id end), 1, 1, "#hs__n_yinghun-choose:::"..player:getLostHp()..":"..player:getLostHp(), self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local n = player:getLostHp()
    local choice = room:askForChoice(player, {"#hs__n_yinghun-draw:::" .. n,  "#hs__n_yinghun-discard:::" .. n}, self.name)
    if choice:startsWith("#hs__n_yinghun-draw") then
      player:broadcastSkillInvoke(self.name, 1)
      room:notifySkillInvoked(player, self.name, "support")
      to:drawCards(n, self.name)
      room:askForDiscard(to, 1, 1, true, self.name, false)
    else
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "control")
      to:drawCards(1, self.name)
      room:askForDiscard(to, n, n, true, self.name, false)
    end
  end,
}
sunjian:addSkill(yinghun)
Fk:loadTranslationTable{
  ['hs__n_sunjian'] = '孙坚',
  ["#hs__n_sunjian"] = "魂佑江东",
  ["illustrator:hs__n_sunjian"] = "凡果",

  ["hs__n_yinghun"] = "英魂",
  [":hs__n_yinghun"] = "准备阶段，你可选择一名其他角色并选择一项：1.令其摸X张牌，然后弃置一张牌；2.令其摸一张牌，然后弃置X张牌（X为你已损失的体力值）。",
  ["#hs__n_yinghun-choose"] = "英魂：你可以令一名其他角色：摸%arg张牌然后弃置一张牌，或摸一张牌然后弃置%arg2张牌",
  ["#hs__n_yinghun-draw"] = "摸%arg张牌，弃置1张牌",
  ["#hs__n_yinghun-discard"] = "摸1张牌，弃置%arg张牌",

  ["$hs__n_yinghun1"] = "以吾魂魄，保佑吾儿之基业。",
  ["$hs__n_yinghun2"] = "不诛此贼三族，则吾死不瞑目！",
  ["~hs__n_sunjian"] = "有埋伏！呃……啊！！",
}

-----
local xiaoqiao = General(extension, "hs__n_xiaoqiao", "wu", 3, 3, General.Female)
local tianxiang = fk.CreateTriggerSkill{
  name = "hs__n_tianxiang",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and (player:getMark("hs__n_tianxiang_damage-turn") == 0 or player:getMark("hs__n_tianxiang_loseHp-turn") == 0)
  end,
  on_cost = function(self, event, target, player, data)
    local tar, card =  player.room:askForChooseCardAndPlayers(player, table.map(player.room:getOtherPlayers(player, false), Util.IdMapper), 1, 1, ".|.|heart|hand", "#hs__n_tianxiang-choose", self.name, true)
    if #tar > 0 and card then
      self.cost_data = {tar[1], card}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data[1])
    local cid = self.cost_data[2]
    room:throwCard(cid, self.name, player, player)

    if to.dead then return true end
    local choices = {}
    if player:getMark("hs__n_tianxiang_loseHp-turn") == 0 then
      table.insert(choices, "hs__n_tianxiang_loseHp")
    end
    if data.from and not data.from.dead and player:getMark("hs__n_tianxiang_damage-turn") == 0 then
      table.insert(choices, "hs__n_tianxiang_damage")
    end
    local choice = room:askForChoice(player, choices, self.name, "#hs__n_tianxiang-choice::"..to.id)
    if choice == "hs__n_tianxiang_loseHp" then
      room:setPlayerMark(player, "hs__n_tianxiang_loseHp-turn", 1)
      room:loseHp(to, 1, self.name)
      if not to.dead and (room:getCardArea(cid) == Card.DrawPile or room:getCardArea(cid) == Card.DiscardPile) then
        room:obtainCard(to, cid, true, fk.ReasonJustMove)
      end
    else
      room:setPlayerMark(player, "hs__n_tianxiang_damage-turn", 1)
      room:damage{
        from = data.from,
        to = to,
        damage = 1,
        skillName = self.name,
      }
      if not to.dead then
        to:drawCards(math.min(to:getLostHp(), 5), self.name)
      end
    end
    return true
  end,
}
local hongyan = fk.CreateFilterSkill{
  name = "hs__n_hongyan",
  card_filter = function(self, to_select, player)
    return to_select.suit == Card.Spade and player:hasSkill(self)
  end,
  view_as = function(self, to_select)
    return Fk:cloneCard(to_select.name, Card.Heart, to_select.number)
  end,
}
local hongyan_maxcards = fk.CreateMaxCardsSkill{
  name = "#hs__n_hongyan_maxcards",
  correct_func = function (self, player)
    if player:hasSkill("hs__n_hongyan") and #table.filter(player:getCardIds(Player.Equip), function (id) return Fk:getCardById(id).suit == Card.Heart or Fk:getCardById(id).suit == Card.Spade end) > 0  then
      return 1
    end
  end,
}
xiaoqiao:addSkill(tianxiang)
hongyan:addRelatedSkill(hongyan_maxcards)
xiaoqiao:addSkill(hongyan)
Fk:loadTranslationTable{
  ['hs__n_xiaoqiao'] = '小乔',
  ["#hs__n_xiaoqiao"] = "矫情之花",
  ["illustrator:hs__n_xiaoqiao"] = "绘聚艺堂",

  ["hs__n_tianxiang"] = "天香",
  [":hs__n_tianxiang"] = "当你受到伤害时，你可弃置一张<font color='red'>♥</font>手牌并选择一名其他角色。你防止此伤害，选择本回合未选择过的一项：1.令来源对其造成1点伤害，其摸X张牌（X为其已损失的体力值且至多为5）；2.令其失去1点体力，其获得牌堆或弃牌堆中你以此法弃置的牌。",
  ["hs__n_hongyan"] = "红颜",
  [":hs__n_hongyan"] = "锁定技，你的黑桃牌视为红桃牌；若你的装备区内有红桃牌，你的手牌上限+1",
  ["#hs__n_tianxiang-choose"] = "天香：弃置一张<font color='red'>♥</font>手牌并选择一名其他角色",
  ["#hs__n_tianxiang-choice"] = "天香：选择一项令 %dest 执行",
  ["hs__n_tianxiang_damage"] = "令其受到1点伤害并摸已损失体力值的牌",
  ["hs__n_tianxiang_loseHp"] = "令其失去1点体力并获得你弃置的牌",

  ["$hs__n_tianxiang1"] = "接着哦~",
  ["$hs__n_tianxiang2"] = "替我挡着~",
  ["~hs__n_xiaoqiao"] = "公瑾…我先走一步……",
}

-----
local taishici = General(extension, "hs__n_taishici", "wu", 4)
local tianyi = fk.CreateActiveSkill{
  name = "hs__n_tianyi",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id and Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player then
      room:addPlayerMark(player, "hs__n_tianyi_win-turn", 1)
    else
      room:addPlayerMark(player, "hs__n_tianyi_lose-turn", 1)
    end
  end,
}
local tianyi_targetmod = fk.CreateTargetModSkill{
  name = "#hs__n_tianyi_targetmod",
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("hs__n_tianyi_win-turn") > 0 and scope == Player.HistoryPhase then
      return 1
    end
  end,
  bypass_distances =  function(self, player, skill)
    return skill.trueName == "slash_skill" and player:getMark("hs__n_tianyi_win-turn") > 0
  end,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:getMark("hs__n_tianyi_win-turn") > 0 then
      return 1
    end
  end,
}
local tianyi_prohibit = fk.CreateProhibitSkill{
  name = "#hs__n_tianyi_prohibit",
  prohibit_use = function(self, player, card)
    return player:getMark("hs__n_tianyi_lose-turn") > 0 and card.trueName == "slash"
  end,
}
tianyi:addRelatedSkill(tianyi_targetmod)
tianyi:addRelatedSkill(tianyi_prohibit)
taishici:addSkill(tianyi)
Fk:loadTranslationTable{
  ['hs__n_taishici'] = '太史慈',
  ["#hs__n_taishici"] = "笃烈之士",
  ["illustrator:hs__n_taishici"] = "Tuu.",

  ["hs__n_tianyi"] = "天义",
  [":hs__n_tianyi"] = "出牌阶段限一次，你可以与一名角色拼点：若你赢，在本回合结束之前，你可以多使用一张【杀】、使用【杀】无距离限制且可以多选择一个目标；"..
  "若你没赢，本回合你不能使用【杀】。",

  ["$hs__n_tianyi1"] = "请助我一臂之力！",
  ["$hs__n_tianyi2"] = "我当要替天行道！",
  ["~hs__n_taishici"] = "大丈夫，当带三尺之剑，立不世之功！",
}

-----
local zhoutai = General(extension, "hs__n_zhoutai", "wu", 4)
local buqu = fk.CreateTriggerSkill{
  name = "hs__n_buqu",
  anim_type = "defensive",
  events = {fk.AskForPeaches},
  frequency = Skill.Compulsory,
  derived_piles = "hs__n_buqu_scar",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.dying
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local scar_id =room:getNCards(1)[1]
    local scar = Fk:getCardById(scar_id)
    player:addToPile("hs__n_buqu_scar", scar_id, true, self.name)
    if player.dead or not table.contains(player:getPile("hs__n_buqu_scar"), scar_id) then return false end
    local success = true
    for _, id in pairs(player:getPile("hs__n_buqu_scar")) do
      if id ~= scar_id then
        local card = Fk:getCardById(id)
        if (card.number == scar.number) then
          success = false
          break
        end
      end
    end
    if success then
      room:recover({
        who = player,
        num = 1 - player.hp,
        recoverBy = player,
        skillName = self.name
      })
    else
      room:throwCard(scar:getEffectiveId(), self.name, player) 
    end
  end,
}
local fenji = fk.CreateTriggerSkill{
  name = "hs__n_fenji",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Finish and target:isKongcheng() and not target.dead
  end,
  on_use = function(self, event, target, player, data)
    target:drawCards(2, self.name)
    if not player.dead then player.room:loseHp(player, 1, self.name) end
  end,
}
zhoutai:addSkill(buqu)
zhoutai:addSkill(fenji)
Fk:loadTranslationTable{
  ['hs__n_zhoutai'] = '周泰',
  ["#hs__n_zhoutai"] = "历战之躯",
  ["illustrator:hs__n_zhoutai"] = "Thinking",

  ["hs__n_buqu"] = "不屈",
  [":hs__n_buqu"] = "锁定技，当你处于濒死状态时，你将牌堆顶的一张牌置于你的武将牌上，称为“创”，若此牌的点数与已有的“创”点数：均不同，则你将体力回复至1点；存在相同，将此牌置入弃牌堆。",
  ["hs__n_fenji"] = "奋激",
  [":hs__n_fenji"] = "一名角色的结束阶段，若其没有手牌，你可令其摸两张牌，然后你失去1点体力。",
  ["hs__n_buqu_scar"] = "创",

  ["$hs__n_buqu1"] = "战如熊虎，不惜躯命！",
  ["$hs__n_buqu2"] = "哼，这点小伤算什么！",
  ["$hs__n_fenji1"] = "百战之身，奋勇驱前！",
  ["$hs__n_fenji2"] = "两肋插刀，愿赴此躯！",
  ["~hs__n_zhoutai"] = "敌众我寡，无力回天……",
}

-----
local lusu = General(extension, "hs__n_lusu", "wu", 3)
local haoshi = fk.CreateTriggerSkill{
  name = "hs__n_haoshi",
  anim_type = "drawcard",
  events = {fk.DrawNCards},
  on_use = function(self, event, target, player, data)
    data.n = data.n + 2
  end,
}
local haoshi_delay = fk.CreateTriggerSkill{
  name = "#hs__n_haoshi_delay",
  events = {fk.AfterDrawNCards},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and player:usedSkillTimes(haoshi.name, Player.HistoryPhase) > 0 and
    #player.player_cards[Player.Hand] > 5 and #player.room.alive_players > 1
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player:getHandcardNum() // 2
    local targets = {}
    local n = 0
    for _, p in ipairs(room.alive_players) do
      if p ~= player then
        if #targets == 0 then
          table.insert(targets, p.id)
          n = p:getHandcardNum()
        else
          if p:getHandcardNum() < n then
            targets = {p.id}
            n = p:getHandcardNum()
          elseif p:getHandcardNum() == n then
            table.insert(targets, p.id)
          end
        end
      end
    end
    local tos, cards = room:askForChooseCardsAndPlayers(player, x, x, targets, 1, 1,
    ".|.|.|hand", "#hs__n_haoshi-give:::" .. x, "hs__n_haoshi", false)
    room:moveCardTo(cards, Card.PlayerHand, room:getPlayerById(tos[1]), fk.ReasonGive, "hs__n_haoshi", nil, false, player.id)
  end,
}
local dimeng = fk.CreateActiveSkill{
  name = "hs__n_dimeng",
  anim_type = "control",
  card_num = 0,
  target_num = 2,
  prompt = "#hs__n_dimeng",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name) == 0 and #Fk:currentRoom().alive_players > 2
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    if to_select == Self.id or #selected > 1 then return false end
    if #selected == 0 then
      return true
    else
      local target1 = Fk:currentRoom():getPlayerById(to_select)
      local target2 = Fk:currentRoom():getPlayerById(selected[1])
      local num, num2 = target1:getHandcardNum(), target2:getHandcardNum()
      if num == 0 and num2 == 0 then
        return false
      end
      local x = #table.filter(Self:getCardIds({Player.Hand, Player.Equip}), function(cid) return not Self:prohibitDiscard(Fk:getCardById(cid)) end)
      return math.abs( num - num2 ) <= x
    end
  end,
  --[[
  feasible = function (self, selected, selected_cards)
    return #selected == 2 and
      math.abs(Fk:currentRoom():getPlayerById(selected[1]):getHandcardNum() - Fk:currentRoom():getPlayerById(selected[2]):getHandcardNum()) == #selected_cards
  end,
  ]]
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target1 = room:getPlayerById(effect.tos[1])
    local target2 = room:getPlayerById(effect.tos[2])
    local num = math.abs(target1:getHandcardNum() - target2:getHandcardNum())
    if num > 0 then
      room:askForDiscard(player, num, num, true, self.name, false, nil, "#hs__n_dimeng-discard:" .. effect.tos[1] .. ":" .. effect.tos[2] .. ":" .. num)
    end
    U.swapHandCards(room, player, target1, target2, self.name)
  end,
}
haoshi:addRelatedSkill(haoshi_delay)
lusu:addSkill(haoshi)
lusu:addSkill(dimeng)
Fk:loadTranslationTable{
  ['hs__n_lusu'] = '鲁肃',
  ["#hs__n_lusu"] = "独断的外交家",
  ["illustrator:hs__n_lusu"] = "LiuHeng",

  ["hs__n_haoshi"] = "好施",
  [":hs__n_haoshi"] = "摸牌阶段，你可以多摸两张牌，然后若你的手牌数大于5，你将半数（向下取整）手牌交给手牌牌最少的一名其他角色。",
  ["hs__n_dimeng"] = "缔盟",
  [":hs__n_dimeng"] = "出牌阶段限一次，你可以选择两名其他角色并弃置X张牌（X为这些角色手牌数差），令这两名角色交换手牌。",
  ["#hs__n_haoshi-give"] = "好施：将%arg张手牌交给手牌最少的一名其他角色",
  ["#hs__n_haoshi_delay"] = "好施",
  ["#hs__n_dimeng"] = "缔盟：选择两名其他角色，点击“确定”后，选择与其手牌数之差等量的牌，这两名角色交换手牌",
  ["#hs__n_dimeng-discard"] = "缔盟：弃置 %arg 张牌，交换%src和%dest的手牌",

  ["$hs__n_haoshi1"] = "拿去拿去，莫跟哥哥客气！",
  ["$hs__n_haoshi2"] = "来来来，见面分一半。",
  ["$hs__n_dimeng1"] = "以和为贵，以和为贵。",
  ["$hs__n_dimeng2"] = "合纵连横，方能以弱胜强。",
  ["~hs__n_lusu"] = "此联盟已破，吴蜀休矣。",
}

-----
local erzhang = General(extension, "hs__n_zhangzhaozhanghong", "wu", 3)
local zhijian = fk.CreateActiveSkill{
  name = "hs__n_zhijian",
  anim_type = "support",
  prompt = "#hs__n_zhijian-active",
  card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip and
      Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and #selected_cards == 1 and to_select ~= Self.id and
    Fk:currentRoom():getPlayerById(to_select):canMoveCardIntoEquip(selected_cards[1], false)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:moveCardIntoEquip(target, effect.cards[1], self.name, true, player)
    if not player.dead then
      room:drawCards(player, 1, self.name)
    end
  end,
}
local guzheng = fk.CreateTriggerSkill{
  name = "hs__n_guzheng",
  anim_type = "support",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(self) and target.phase == Player.Discard then
      local room = player.room
      local guzheng_hand, guzheng_all, cards = {}, {}, {}
      local phase_event = room.logic:getCurrentEvent():findParent(GameEvent.Phase, true)
      if phase_event == nil then return false end
      local end_id = phase_event.id
      room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if not table.contains(cards, id) then
              table.insert(cards, id)
              if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and
                room:getCardArea(id) == Card.DiscardPile then
                table.insert(guzheng_all, id)
                if move.from == target.id and info.fromArea == Card.PlayerHand then
                  table.insert(guzheng_hand, id)
                end
              end
            end
          end
        end
        return false
      end, end_id)
      if #guzheng_hand > 0 then
        self.cost_data = {guzheng_hand, guzheng_all}
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if room:askForSkillInvoke(player, self.name, nil, "#hs__n_guzheng-invoke::"..target.id) then
      room:doIndicate(player.id, {target.id})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local guzheng_hand, guzheng_all = self.cost_data[1], self.cost_data[2]
    guzheng_all = table.reverse(guzheng_all)
    local to_return = {guzheng_hand[1]}
    local choice = "hs__n_guzheng_no"
    if #guzheng_all > 1 then
      to_return, choice = U.askforChooseCardsAndChoice(player, guzheng_hand, {"hs__n_guzheng_yes", "hs__n_guzheng_no"},
      self.name, "#hs__n_guzheng-title::" .. target.id, {}, 1, 1, guzheng_all)
    end
    local moveInfos = {}
    table.insert(moveInfos, {
      ids = to_return,
      to = target.id,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonGive,
      proposer = player.id,
      skillName = self.name,
    })
    table.removeOne(guzheng_all, to_return[1])
    if choice == "hs__n_guzheng_yes" and #guzheng_all > 0 then
      table.insert(moveInfos, {
        ids = guzheng_all,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonPrey,
        proposer = player.id,
        skillName = self.name,
      })
    end
    room:moveCards(table.unpack(moveInfos))
  end,
}
erzhang:addSkill(zhijian)
erzhang:addSkill(guzheng)
Fk:loadTranslationTable{
  ['hs__n_zhangzhaozhanghong'] = '张昭张纮',
  ["#hs__n_zhangzhaozhanghong"] = "经天纬地",
  ["illustrator:hs__n_zhangzhaozhanghong"] = "废柴男",

  ["hs__n_zhijian"] = "直谏",
  [":hs__n_zhijian"] = "出牌阶段，你可以将手牌中的一张装备牌置于其他角色的装备区里，然后摸一张牌。",
  ["hs__n_guzheng"] = "固政",
  [":hs__n_guzheng"] = "其他角色的弃牌阶段结束时，你可以将此阶段中其弃置的一张手牌交给该角色，然后你可以获得其余此阶段内弃置的牌。",
  ["#hs__n_zhijian-active"] = "发动直谏，选择一张装备牌置入其他角色的装备区",
  ["#hs__n_guzheng-invoke"] = "你可以发动固政，令%dest获得其此次弃置的牌中的一张，然后你可获得剩余牌",
  ["#hs__n_guzheng-title"] = "固政：选择一张牌还给 %dest",
  ["hs__n_guzheng_yes"] = "确定，获得剩余牌",
  ["hs__n_guzheng_no"] = "确定，不获得剩余牌",

  ["$hs__n_zhijian1"] = "请恕老臣直言！",
  ["$hs__n_zhijian2"] = "为臣者，当冒死以谏！",
  ["$hs__n_guzheng1"] = "固国安邦，居当如是。",
  ["$hs__n_guzheng2"] = "今当稳固内政，以御外患。",
  ["~hs__n_zhangzhaozhanghong"] = "竭力尽智，死而无憾。",
}

-----
local dingfeng = General(extension, "hs__n_dingfeng", "wu", 4)
local duanbing = fk.CreateTriggerSkill{
  name = "hs__n_duanbing",
  anim_type = "offensive",
  events = {fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and
      table.find(player.room:getUseExtraTargets(data), function(id)
        return player:distanceTo(player.room:getPlayerById(id)) == 1
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getUseExtraTargets(data), function(id)
      return player:distanceTo(room:getPlayerById(id)) == 1
    end)
    local tos = room:askForChoosePlayers(player, targets, 1, 1, "#hs__n_duanbing-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    table.insert(data.tos, {self.cost_data})
  end,
}
local fenxun = fk.CreateActiveSkill{
  name = "hs__n_fenxun",
  anim_type = "offensive",
  card_num = 1,
  target_num = 1,
  prompt = "#hs__n_fenxun",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isNude()
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected, cards)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:addTableMark(player, "hs__n_fenxun-turn", effect.tos[1])
    room:throwCard(effect.cards, self.name, player, player)
  end,
}
local fenxun_distance = fk.CreateDistanceSkill{
  name = "#hs__n_fenxun_distance",
  fixed_func = function(self, from, to)
    if table.contains(from:getTableMark("hs__n_fenxun-turn"), to.id) then
      return 1
    end
  end,
}
fenxun:addRelatedSkill(fenxun_distance)
dingfeng:addSkill(duanbing)
dingfeng:addSkill(fenxun)
Fk:loadTranslationTable{
  ["hs__n_dingfeng"] = "丁奉",
  ["#hs__n_dingfeng"] = "清侧重臣",
  ["illustrator:hs__n_dingfeng"] = "魔鬼鱼",

  ["hs__n_duanbing"] = "短兵",
  [":hs__n_duanbing"] = "你使用【杀】时可以额外选择一名距离为1的其他角色为目标。",
  ["hs__n_fenxun"] = "奋迅",
  [":hs__n_fenxun"] = "出牌阶段限一次，你可以弃置一张牌并选择一名其他角色，令你与其的距离视为1，直到回合结束。",
  ["#hs__n_duanbing-choose"] = "短兵：你可以额外选择一名距离为1的其他角色为目标",
  ["#hs__n_fenxun"] = "奋迅：弃一张牌，你与一名角色的距离视为1直到回合结束",

  ["$hs__n_duanbing1"] = "众将官，短刀出鞘。",
  ["$hs__n_duanbing2"] = "短兵轻甲也可取汝性命！",
  ["$hs__n_fenxun1"] = "取封侯爵赏，正在今日！",
  ["$hs__n_fenxun2"] = "给我拉过来！",
  ["~hs__n_dingfeng"] = "这风，太冷了……",
}

-----
local huatuo = General(extension, "hs__n_huatuo", "qun", 3)
local jijiu = fk.CreateViewAsSkill{
  name = "hs__n_jijiu",
  anim_type = "support",
  pattern = "peach",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    return Fk:getCardById(to_select).color == Card.Red
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("peach")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, res)
    return player.phase == Player.NotActive and not res
  end,
}
local chuli = fk.CreateActiveSkill{
  name = "hs__n_chuli",
  anim_type = "control",
  card_num = 0,
  min_target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isNude()
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    local room = Fk:currentRoom()
    local target = room:getPlayerById(to_select)
    return to_select ~= Self.id and not target:isNude() and #selected < 3 and
      table.every(selected, function(id) return not H.compareKingdomWith(target, room:getPlayerById(id)) end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.clone(effect.tos)
    table.insert(targets, 1, effect.from)
    room:sortPlayersByAction(targets)
    for _, id in ipairs(targets) do
      local target = room:getPlayerById(id)
      if not target:isNude() then
        local c = room:askForCardChosen(player, target, "he", self.name)
        room:throwCard({c}, self.name, target, player)
        if Fk:getCardById(c).suit == Card.Spade then
          room:addPlayerMark(target, "_hs__n_chuli-phase", 1)
        end
      end
    end
    for _, id in ipairs(targets) do
      local target = room:getPlayerById(id)
      if target:getMark("_hs__n_chuli-phase") > 0 and not target.dead then
        room:setPlayerMark(target, "_hs__n_chuli-phase", 0)
        target:drawCards(1, self.name)
      end
    end
  end,
}
huatuo:addSkill(jijiu)
huatuo:addSkill(chuli)
Fk:loadTranslationTable{
  ["hs__n_huatuo"] = "华佗",
  ["#hs__n_huatuo"] = "神医",
  ["illustrator:hs__n_huatuo"] = "琛·美弟奇",

  ["hs__n_jijiu"] = "急救",
  [":hs__n_jijiu"] = "你的回合外，你可以将一张红色牌当【桃】使用。",
  ["hs__n_chuli"] = "除疠",
  [":hs__n_chuli"] = "出牌阶段限一次，你可选择至多三名势力各不相同或未确定势力的其他角色，然后你弃置你和这些角色的各一张牌。被弃置♠牌的角色各摸一张牌。",

  ["$hs__n_jijiu1"] = "救死扶伤，悬壶济世。",
  ["$hs__n_jijiu2"] = "妙手仁心，药到病除。",
  ["$hs__n_chuli1"] = "病去，如抽丝。",
  ["$hs__n_chuli2"] = "病入膏肓，需下猛药。",
  ["~hs__n_huatuo"] = "生老病死，命不可违。",
}

local lvbu = General(extension, "hs__n_lvbu", "qun", 5)
lvbu:addCompanions("hs__n_diaochan")
local wushuang = fk.CreateTriggerSkill{
  name = "hs__n_wushuang",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then
      return false
    end
    if event == fk.TargetSpecified then
      return target == player and table.contains({ "slash", "duel" }, data.card.trueName)
    else
      return data.to == player.id and data.card.trueName == "duel"
    end
  end,
  on_use = function(self, event, target, player, data)
    data.fixedResponseTimes = data.fixedResponseTimes or {}
    if data.card.trueName == "slash" then
      data.fixedResponseTimes["jink"] = 2
    else
      data.fixedResponseTimes["slash"] = 2
      data.fixedAddTimesResponsors = data.fixedAddTimesResponsors or {}
      table.insert(data.fixedAddTimesResponsors, (event == fk.TargetSpecified and data.to or data.from))
    end
  end,
}
lvbu:addSkill(wushuang)
Fk:loadTranslationTable{
  ["hs__n_lvbu"] = "吕布",
  ["#hs__n_lvbu"] = "戟指中原",
  ["illustrator:hs__n_lvbu"] = "凡果",

  ["hs__n_wushuang"] = "无双",
  [":hs__n_wushuang"] = "锁定技，当你使用【杀】指定目标后，其使用【闪】抵消此【杀】的方式改为需连续使用两张【闪】；当你使用【决斗】指定目标后，或当你成为【决斗】的目标后，你令其打出【杀】响应此【决斗】的方式改为需连续打出两张【杀】。",

  ["$hs__n_wushuang1"] = "谁能挡我！",
  ["$hs__n_wushuang2"] = "神挡杀神，佛挡杀佛！",
  ["~hs__n_lvbu"] = "不可能！",
}

-----
local diaochan = General(extension, "hs__n_diaochan", "qun", 3, 3, General.Female)
local lijian = fk.CreateActiveSkill{
  name = "hs__n_lijian",
  anim_type = "offensive",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  target_filter = function(self, to_select, selected)
    return #selected < 2 and to_select ~= Self.id and
      Fk:currentRoom():getPlayerById(to_select).gender == General.Male
  end,
  target_num = 2,
  min_card_num = 1,
  on_use = function(self, room, use)
    local player = room:getPlayerById(use.from)
    room:throwCard(use.cards, self.name, player, player)
    local duel = Fk:cloneCard("duel")
    duel.skillName = self.name
    local new_use = { ---@type CardUseStruct
      from = use.tos[2],
      tos = { { use.tos[1] } },
      card = duel,
    }
    room:useCard(new_use)
  end,
}
local biyue = fk.CreateTriggerSkill{
  name = "hs__n_biyue",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
      and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}
diaochan:addSkill(lijian)
diaochan:addSkill(biyue)
Fk:loadTranslationTable{
  ["hs__n_diaochan"] = "貂蝉",
  ["#hs__n_diaochan"] = "绝世的舞姬",
  ["illustrator:hs__n_diaochan"] = "LiuHeng",

  ["hs__n_lijian"] = "离间",
  [":hs__n_lijian"] = "出牌阶段限一次，你可弃置一张牌并选择两名其他男性角色，后选择的角色视为对先选择的角色使用一张【决斗】。",
  ["hs__n_biyue"] = "闭月",
  [":hs__n_biyue"] = "结束阶段，你可以摸一张牌。",

  ["$hs__n_lijian1"] = "嗯呵呵~~呵呵~~",
  ["$hs__n_lijian2"] = "夫君，你要替妾身做主啊……",
  ["$hs__n_biyue1"] = "失礼了~",
  ["$hs__n_biyue2"] = "羡慕吧~",
  ["~hs__n_diaochan"] = "父亲大人，对不起……",
}

-----
local yuanshao = General(extension, "hs__n_yuanshao", "qun", 4)
yuanshao:addCompanions("hs__n_yanliangwenchou")
local luanji = fk.CreateViewAsSkill{
  name = "hs__n_luanji",
  anim_type = "offensive",
  pattern = "archery_attack",
  card_filter = function(self, to_select, selected)
    if #selected == 2 or Fk:currentRoom():getCardArea(to_select) ~= Player.Hand then return false end
    local record = Self:getTableMark("@hs__n_luanji-turn")
    return not table.contains(record, Fk:getCardById(to_select):getSuitString(true))
  end,
  view_as = function(self, cards)
    if #cards ~= 2 then
      return nil
    end
    local c = Fk:cloneCard("archery_attack")
    c.skillName = "hs__n_luanji"
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    local record = player:getTableMark("@hs__n_luanji-turn")
    local cards = use.card.subcards
    for _, cid in ipairs(cards) do
      local suit = Fk:getCardById(cid):getSuitString(true)
      if suit ~= "log_nosuit" then table.insertIfNeed(record, suit) end
    end
    room:setPlayerMark(player, "@hs__n_luanji-turn", record)
  end
}
local luanji_draw = fk.CreateTriggerSkill{
  name = "#hs__n_luanji_draw",
  anim_type = "drawcard",
  visible = false,
  events = {fk.CardRespondFinished},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or data.card.name ~= "jink" or player.dead then return false end
    if data.responseToEvent and table.contains(data.responseToEvent.card.skillNames, "hs__n_luanji") then
      local yuanshao = data.responseToEvent.from
      if yuanshao and H.compareKingdomWith(player, player.room:getPlayerById(yuanshao)) then
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#hs__n_luanji-draw")
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}
luanji:addRelatedSkill(luanji_draw)
yuanshao:addSkill(luanji)
Fk:loadTranslationTable{
  ["hs__n_yuanshao"] = "袁绍",
  ["#hs__n_yuanshao"] = "高贵的名门",
  ["illustrator:hs__n_yuanshao"] = "北辰菌",

  ["hs__n_luanji"] = "乱击",
  [":hs__n_luanji"] = "你可将两张手牌当【万箭齐发】使用（不能使用此回合以此法使用过的花色），当与你势力相同的角色打出【闪】响应此牌结算结束后，其可摸一张牌。",
  ["@hs__n_luanji-turn"] = "乱击",
  ["#hs__n_luanji-draw"] = "乱击：你可摸一张牌",
  ["#hs__n_luanji_draw"] = "乱击",

  ["$hs__n_luanji1"] = "弓箭手，准备放箭！",
  ["$hs__n_luanji2"] = "全都去死吧！",
  ["~hs__n_yuanshao"] = "老天不助我袁家啊！",
}

local sx = General(extension, 'hs__n_yanliangwenchou', 'qun', 4)
local shuangxiong = fk.CreateViewAsSkill{
  name = "hs__n_shuangxiong",
  anim_type = "offensive",
  pattern = "duel",
  prompt = function()
    local mark = Self:getMark("@hs__n_shuangxiong-turn")
    local color = ""
    if #mark == 1 then
      if mark[1] == "red" then
        color = "black"
      else
        color = "red"
      end
    end
    return "#hs__n_shuangxiong:::"..color
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    local color = Fk:getCardById(to_select):getColorString()
    if color == "red" then
      color = "black"
    elseif color == "black" then
      color = "red"
    else
      return false
    end
    return table.contains(Self:getHandlyIds(true), to_select) and table.contains(Self:getMark("@hs__n_shuangxiong-turn"), color)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("duel")
    c:addSubcard(cards[1])
    c.skillName = self.name
    return c
  end,
  enabled_at_play = function(self, player)
    return type(player:getMark("@hs__n_shuangxiong-turn")) == "table"
  end,
  enabled_at_response = function(self, player, resp)
    return type(player:getMark("@hs__n_shuangxiong-turn")) == "table" and not resp
  end,
}
local shuangxiongJudge = fk.CreateTriggerSkill{
  name = "#hs__n_shuangxiongJudge",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  mute = true,
  main_skill = shuangxiong,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(shuangxiong) and player.phase == Player.Draw
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = "hs__n_shuangxiong",
    }
    room:notifySkillInvoked(player, "hs__n_shuangxiong", "offensive")
    player:broadcastSkillInvoke("hs__n_shuangxiong")
    player:revealBySkillName("hs__n_shuangxiong") -- 先这样
    room:judge(judge)
    local color = judge.card:getColorString()
    if color == "nocolor" then return end
    local colorsRecorded = player:getTableMark("@hs__n_shuangxiong-turn")
    table.insertIfNeed(colorsRecorded, color)
    room:setPlayerMark(player, "@hs__n_shuangxiong-turn", colorsRecorded)
    return true
  end,
}
local shuangxiongGet = fk.CreateTriggerSkill{
  name = "#hs__n_shuangxiong_get",
  mute = true,
  events = {fk.FinishJudge},
  can_trigger = function(self, event, target, player, data)
    return target == player and not player.dead and data.reason == "hs__n_shuangxiong" and
    player.room:getCardArea(data.card) == Card.Processing
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:obtainCard(player.id, data.card, true, fk.ReasonJustMove, player.id, "hs__n_shuangxiong")
  end,
}
shuangxiong:addRelatedSkill(shuangxiongJudge)
shuangxiong:addRelatedSkill(shuangxiongGet)
sx:addSkill(shuangxiong)
Fk:loadTranslationTable{
  ['hs__n_yanliangwenchou'] = '颜良文丑',
  ["#hs__n_yanliangwenchou"] = "虎狼兄弟",
  ["illustrator:hs__n_yanliangwenchou"] = "KayaK",

  ["hs__n_shuangxiong"] = "双雄",
  [":hs__n_shuangxiong"] = "摸牌阶段，你可以放弃摸牌并进行一次判定：你获得此判定牌并且此回合可以将任意一张与该判定牌不同颜色的手牌当【决斗】使用。",
  ["@hs__n_shuangxiong-turn"] = "双雄",
  ["#hs__n_shuangxiongJudge"] = "双雄",
  ["#hs__n_shuangxiong_get"] = "双雄",
  ["#hs__n_shuangxiong"] = "双雄：你可以将一张%arg手牌当【决斗】使用",

  ["$hs__n_shuangxiong1"] = "吾乃河北上将颜良文丑是也！",
  ["$hs__n_shuangxiong2"] = "快来与我等决一死战！",
  ["~hs__n_yanliangwenchou"] = "这红脸长须大将是……",
}

-----
local jiaxu = General(extension, 'hs__n_jiaxu', 'qun', 3)
local wansha = fk.CreateTriggerSkill{
  name = "hs__n_wansha",
  anim_type = "offensive",
  frequency = Skill.Compulsory,

  refresh_events = {fk.EnterDying},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase ~= Player.NotActive and table.contains(player.player_skills, self)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, self.name)
    player:broadcastSkillInvoke(self.name)
  end,
}
local wansha_prohibit = fk.CreateProhibitSkill{
  name = "#hs__n_wansha_prohibit",
  prohibit_use = function(self, player, card)
    if card.name == "peach" and not player.dying then
      return table.find(Fk:currentRoom().alive_players, function(p)
        return p.phase ~= Player.NotActive and p:hasSkill(wansha) and p ~= player and table.contains(p.player_skills, wansha)
      end)
    end
  end,
}
local luanwu = fk.CreateActiveSkill{
  name = "hs__n_luanwu",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  frequency = Skill.Limited,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = room:getOtherPlayers(player)
    room:doIndicate(player.id, table.map(targets, Util.IdMapper))
    for _, target in ipairs(targets) do
      if not target.dead then
        local other_players = table.filter(room:getOtherPlayers(target, false), function(p) return not p:isRemoved() end)
        local luanwu_targets = table.map(table.filter(other_players, function(p2)
          return table.every(other_players, function(p1)
            return target:distanceTo(p1) >= target:distanceTo(p2)
          end)
        end), Util.IdMapper)
        local use = room:askForUseCard(target, "slash", "slash", "#hs__n_luanwu-use", true, {exclusive_targets = luanwu_targets, bypass_times = true})
        if use then
          use.extraUse = true
          room:useCard(use)
        else
          room:loseHp(target, 1, self.name)
        end
      end
    end
  end,
}
local weimu = fk.CreateTriggerSkill{
  name = "hs__n_weimu",
  anim_type = "defensive",
  events = { fk.TargetConfirming, fk.BeforeCardsMove },
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.TargetConfirming then
      return target == player and data.card.color == Card.Black and data.card:isCommonTrick()
    elseif event == fk.BeforeCardsMove then
      local id = 0
      local source = player
      local room = player.room
      local c
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerJudge then
          for _, info in ipairs(move.moveInfo) do
            id = info.cardId
            if info.fromArea == Card.PlayerJudge then
              source = room:getPlayerById(move.from) or player
            else
              source = player
            end
            c = source:getVirualEquip(id)
            --FIXME：巨大隐患，延时锦囊的virtual_equips在置入判定区的事件被篡改，或者判定阶段自然流程以外的方式离开判定区时不会清理
            if not c then c = Fk:getCardById(id) end
            if c.sub_type == Card.SubtypeDelayedTrick and c.color == Card.Black then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirming then
      AimGroup:cancelTarget(data, player.id)
      return true
    elseif event == fk.BeforeCardsMove then
      local source = player
      local mirror_moves = {}
      local ids = {}
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Card.PlayerJudge then
          local move_info = {}
          local mirror_info = {}
          for _, info in ipairs(move.moveInfo) do
            local id = info.cardId
            if info.fromArea == Card.PlayerJudge then
              source = room:getPlayerById(move.from) or player
            else
              source = player
            end
            local c = source:getVirualEquip(id)
            if not c then c = Fk:getCardById(id) end
            if c.sub_type == Card.SubtypeDelayedTrick and c.color == Card.Black then
              table.insert(mirror_info, info)
              table.insert(ids, id)
            else
              table.insert(move_info, info)
            end
          end
          if #mirror_info > 0 then
            move.moveInfo = move_info
            local mirror_move = table.clone(move)
            mirror_move.to = nil
            mirror_move.toArea = Card.DiscardPile
            mirror_move.moveInfo = mirror_info
            table.insert(mirror_moves, mirror_move)
          end
        end
      end
      table.insertTable(data, mirror_moves)
    end
  end
}
jiaxu:addSkill(wansha)
jiaxu:addSkill(luanwu)
wansha:addRelatedSkill(wansha_prohibit)
jiaxu:addSkill(weimu)
Fk:loadTranslationTable{
  ['hs__n_jiaxu'] = '贾诩',
  ["#hs__n_jiaxu"] = "冷酷的毒士",
  ["illustrator:hs__n_jiaxu"] = "绘聚艺堂",

  ["hs__n_wansha"] = "完杀",
  [":hs__n_wansha"] = "锁定技，除进行濒死流程的角色以外的其他角色于你的回合内不能使用【桃】。",
  ["hs__n_luanwu"] = "乱武",
  [":hs__n_luanwu"] = "限定技，出牌阶段，你可选择所有其他角色，这些角色各需对包括距离最小的另一名角色在内的角色使用【杀】，否则失去1点体力。",
  ['hs__n_weimu'] = '帷幕',
  [':hs__n_weimu'] = '锁定技，当你成为黑色锦囊牌的目标时，取消之。',

  ["$hs__n_wansha1"] = "神仙难救，神仙难救啊。",
  ["$hs__n_wansha2"] = "我要你三更死，谁敢留你到五更！",
  ["$hs__n_luanwu1"] = "哼哼哼……坐山观虎斗！",
  ["$hs__n_luanwu2"] = "哭喊吧，哀求吧，挣扎吧，然后，死吧！",
  ["$hs__n_weimu1"] = "此计伤不到我。",
  ["$hs__n_weimu2"] = "你奈我何！",
  ["~hs__n_jiaxu"] = "我的时辰也到了……",
}

-----
local pangde = General(extension, "hs__n_pangde", "qun", 4)
local pangde__mashu = fk.CreateDistanceSkill{
  name = "hs__n_pande__mashu",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      return -1
    end
  end,
}
local jianchu = fk.CreateTriggerSkill{
  name = "hs__n_jianchu",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if not (target == player and player:hasSkill(self)) then return end
    local to = player.room:getPlayerById(data.to)
    return data.card.trueName == "slash" and not to:isNude()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local id = room:askForCardChosen(player, to, "he", self.name)
    room:throwCard({id}, self.name, to, player)
    local card = Fk:getCardById(id)
    if card.type == Card.TypeEquip then
      data.disresponsive = true
    else
      if not to.dead then
        local cardlist = Card:getIdList(data.card)
        if #cardlist > 0 and table.every(cardlist, function(id) return room:getCardArea(id) == Card.Processing end) then
          room:obtainCard(to.id, data.card, false)
        end
      end
    end
  end,
}
pangde:addSkill(jianchu)
pangde:addSkill(pangde__mashu)
Fk:loadTranslationTable{
  ["hs__n_pangde"] = "庞德",
  ["#hs__n_pangde"] = "人马一体",
  ["illustrator:hs__n_pangde"] = "凝聚永恒",

  ["hs__n_jianchu"] = "鞬出",
  [":hs__n_jianchu"] = "当你使用【杀】指定目标后，你可以弃置该角色的一张牌，若此牌：为装备牌，其不能使用【闪】抵消此【杀】；不为装备牌，其获得此【杀】。",
  ["hs__n_pande__mashu"] = "马术",
  [":hs__n_pande__mashu"] = "锁定技，你与其他角色的距离-1。",

  ["$hs__n_jianchu1"] = "你，可敢挡我！",
  ["$hs__n_jianchu2"] = "我要杀你们个片甲不留！",
  ["~hs__n_pangde"] = "四面都是水……我命休矣。",
}

-----
local zhangjiao = General(extension, "hs__n_zhangjiao", 'qun', 3)
local leiji = fk.CreateTriggerSkill{
  name = "hs__n_leiji",
  anim_type = "offensive",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.card.name == "jink"
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), function (p)
      return p.id end), 1, 1, "#hs__n_leiji-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = room:getPlayerById(self.cost_data)
    local judge = {
      who = tar,
      reason = self.name,
      pattern = ".|.|spade",
    }
    room:judge(judge)
    if judge.card.suit == Card.Spade then
      room:damage{
        from = player,
        to = tar,
        damage = 2,
        damageType = fk.ThunderDamage,
        skillName = self.name,
      }
    end
end,
}
local guidao = fk.CreateTriggerSkill{
  name = "hs__n_guidao",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForResponse(player, self.name, ".|.|spade,club|hand,equip", "#hs__n_guidao-ask::" .. target.id .. ":" .. data.reason, true)
    if card ~= nil then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:retrial(self.cost_data, player, data, self.name, true)
  end,
}
zhangjiao:addSkill(leiji)
zhangjiao:addSkill(guidao)
Fk:loadTranslationTable{
  ['hs__n_zhangjiao'] = '张角',
  ["#hs__n_zhangjiao"] = "天公将军",
  ["illustrator:hs__n_zhangjiao"] = "LiuHeng",

  ["hs__n_leiji"] = "雷击",
  [":hs__n_leiji"] = "当你使用或打出【闪】时，你可以令一名角色进行判定，若结果为♠，你对其造成2点雷电伤害。",
  ["hs__n_guidao"] = "鬼道",
  [":hs__n_guidao"] = "当一名角色的判定牌生效前，你可以打出一张黑色牌替换之。",

  ["$hs__n_leiji1"] = "以我之真气，合天地之造化！",
  ["$hs__n_leiji2"] = "雷公助我！",
  ["$hs__n_guidao1"] = "天下大势，为我所控。",
  ['$hs__n_guidao2'] = "哼哼哼哼~",
  ["~hs__n_zhangjiao"] = "黄天…也死了……",
}

-----
local caiwenji = General(extension, "hs__n_caiwenji", "qun", 3, 3, General.Female)
local beige = fk.CreateTriggerSkill{
  name = "hs__n_beige",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and data.card and data.card.trueName == "slash" and not data.to.dead and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local card = room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#hs__n_beige-invoke::"..target.id, true)
    if #card > 0 then
      room:doIndicate(player.id, {target.id})
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data, self.name, player, player)
    if target.dead then return false end
    local judge = {
      who = target,
      reason = self.name,
      pattern = ".",
    }
    room:judge(judge)
    if judge.card.suit == Card.Heart then
      if not target.dead and target:isWounded() then
        room:recover{
          who = target,
          num = 1,
          recoverBy = player,
          skillName = self.name
        }
      end
    elseif judge.card.suit == Card.Diamond then
      if not target.dead then
        target:drawCards(2, self.name)
      end
    elseif judge.card.suit == Card.Club then
      if data.from and not data.from.dead then
        room:askForDiscard(data.from, 2, 2, true, self.name, false)
      end
    elseif judge.card.suit == Card.Spade then
      if data.from and not data.from.dead then
        data.from:turnOver()
      end
    end
  end,
}
local duanchang = fk.CreateTriggerSkill{
  name = "hs__n_duanchang",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, false, true) and data.damage and data.damage.from and not data.damage.from.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.damage.from ---@type ServerPlayer
    local choices = {}
    if not to.general:startsWith("blank_") then
      table.insert(choices, to.general ~= "anjiang" and to.general or "mainGeneral")
    end
    if not to.deputyGeneral:startsWith("blank_") then
      table.insert(choices, to.deputyGeneral ~= "anjiang" and to.deputyGeneral or "deputyGeneral")
    end
    if #choices == 0 then return false end
    local choice = room:askForChoice(player, choices, self.name, "#hs__n_duanchang-ask::" .. to.id)
    room:addTableMark(to, "@hs__n_duanchang", choice)
    local _g = (choice == "mainGeneral" or choice == to.general) and to.general or to.deputyGeneral
    if _g ~= "anjiang" then
      local skills = {}
      for _, skill_name in ipairs(Fk.generals[_g]:getSkillNameList(true)) do
        table.insertIfNeed(skills, skill_name)
      end
      if #skills > 0 then
        room:handleAddLoseSkills(to, "-"..table.concat(skills, "|-"), nil, true, false)
      end
    else
      _g = choice == "mainGeneral" and to:getMark("__heg_general") or to:getMark("__heg_deputy")
      local general = Fk.generals[_g]
      for _, s in ipairs(general:getSkillNameList()) do
        local skill = Fk.skills[s]
        to:loseFakeSkill(skill)
      end
      room:addTableMark(to, "_hs__n_duanchang_anjiang", _g)
    end
  end,

  refresh_events = {fk.GeneralShown},
  can_refresh = function(self, event, target, player, data)
    if target == player and type(player:getMark("_hs__n_duanchang_anjiang")) == "table" then
      for _, v in pairs(data) do
        if table.contains(player:getMark("_hs__n_duanchang_anjiang"), v) then return true end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local skills = {}
    for _, v in pairs(data) do
      if table.contains(player:getMark("_hs__n_duanchang_anjiang"), v) then
        for _, skill_name in ipairs(Fk.generals[v]:getSkillNameList(true)) do
          table.insertIfNeed(skills, skill_name)
        end
        if #skills > 0 then
          player.room:handleAddLoseSkills(player, "-"..table.concat(skills, "|-"), nil, true, false)
        end
      end
    end
  end,
}
caiwenji:addSkill(beige)
caiwenji:addSkill(duanchang)
Fk:loadTranslationTable{
  ["hs__n_caiwenji"] = "蔡文姬",
  ["#hs__n_caiwenji"] = "异乡的孤女",
  ["illustrator:hs__n_caiwenji"] = "SoniaTang",

  ["hs__n_beige"] = "悲歌",
  [":hs__n_beige"] = "当一名角色受到【杀】造成的伤害后，你可以弃置一张牌，然后令其进行判定，若结果为：<font color='red'>♥</font>，其回复1点体力；"..
  "<font color='red'>♦</font>，其摸两张牌；♣，伤害来源弃置两张牌；♠，伤害来源翻面。",
  ["hs__n_duanchang"] = "断肠",
  [":hs__n_duanchang"] = "锁定技，当你死亡时，你令杀死你的角色失去一张武将牌上的所有技能。",
  ["#hs__n_beige-invoke"] = "悲歌：%dest 受到伤害，你可以弃置一张牌令其判定，根据花色执行效果",
  ["#hs__n_duanchang-ask"] = "断肠：令 %dest 失去一张武将牌上的所有技能",
  ["@hs__n_duanchang"] = "断肠",

  ["$hs__n_beige1"] = "悲歌可以当泣，远望可以当归。",
  ["$hs__n_beige2"] = "制兹八拍兮拟排忧，何知曲成兮心转愁。",
  ["$hs__n_duanchang1"] = "流落异乡愁断肠。",
  ["$hs__n_duanchang2"] = "日东月西兮徒相望，不得相随兮空断肠。",
  ["~hs__n_caiwenji"] = "人生几何时，怀忧终年岁。",
}

-----
local mateng = General(extension, "hs__n_mateng", "qun", 4)
local xiongyi = fk.CreateActiveSkill{
  name = "hs__n_xiongyi",
  anim_type = "drawcard",
  frequency = Skill.Limited,
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local targets = table.map(table.filter(room.alive_players, function(p) return H.compareKingdomWith(p, player) end), Util.IdMapper)
    room:sortPlayersByAction(targets)
    for _, p in ipairs(targets) do
      p = room:getPlayerById(p)
      if not p.dead then
        p:drawCards(3, self.name)
      end
    end
    if player.dead or player.kingdom == "unknown" then return false end
    local kingdomMapper = H.getKingdomPlayersNum(room)
    local num = kingdomMapper[H.getKingdom(player)]
    for _, n in pairs(kingdomMapper) do
      if n < num then return false end
    end
    if player:isWounded() then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}
local mateng_mashu = fk.CreateDistanceSkill{
  name = "hs__n_mateng__mashu",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if from:hasSkill(self) then
      return -1
    end
  end,
}
mateng:addSkill(xiongyi)
mateng:addSkill(mateng_mashu)
Fk:loadTranslationTable{
  ["hs__n_mateng"] = "马腾",
  ["#hs__n_mateng"] = "驰骋西陲",
  ["desinger:hs__n_mateng"] = "淬毒",
  ["illustrator:hs__n_mateng"] = "DH",

  ["hs__n_xiongyi"] = "雄异",
  [":hs__n_xiongyi"] = "限定技，出牌阶段，你可令与你势力相同的所有角色各摸三张牌，然后若你的势力角色数为全场最少，你回复1点体力。",
  ["hs__n_mateng__mashu"] = "马术",
  [":hs__n_mateng__mashu"] = "锁定技，你与其他角色的距离-1。",

  ["$hs__n_xiongyi1"] = "弟兄们，我们的机会来啦！",
  ["$hs__n_xiongyi2"] = "此时不战，更待何时！",
  ["~hs__n_mateng"] = "儿子，为爹报仇啊！",
}

-----
local kongrong = General(extension, "hs__n_kongrong", "qun", 3)
local mingshi = fk.CreateTriggerSkill{
  name = "hs__n_mingshi",
  anim_type = "defensive",
  events = {fk.DamageInflicted},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and 
      (data.from.general == "anjiang" or data.from.deputyGeneral == "anjiang")
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage - 1
  end,
}
local lirang = fk.CreateTriggerSkill{
  name = "hs__n_lirang",
  anim_type = "support",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    for _, move in ipairs(data) do
      if move.from == player.id and move.moveReason == fk.ReasonDiscard and move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            return true
          end
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if not player:hasSkill(self) then break end
      if move.from == player.id and move.moveReason == fk.ReasonDiscard and move.toArea == Card.DiscardPile then
        local cids = {}
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
            table.insertIfNeed(cids, info.cardId)
          end
        end
        self:doCost(event, nil, player, cids)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local ids = data
    local room = player.room
    local fakemove = {
      toArea = Card.PlayerHand,
      to = player.id,
      moveInfo = table.map(ids, function(id) return {cardId = id, fromArea = Card.DiscardPile} end),
      moveReason = fk.ReasonJustMove,
    }
    room:notifyMoveCards({player}, {fakemove})
    for _, id in ipairs(ids) do
      room:setCardMark(Fk:getCardById(id), "lirang", 1)
    end
    while table.find(ids, function(id) return Fk:getCardById(id):getMark("lirang") > 0 end) do
      if not room:askForUseActiveSkill(player, "#hs__n_lirang_active", "#lirang-give", true) then
        for _, id in ipairs(ids) do
          room:setCardMark(Fk:getCardById(id), "lirang", 0)
        end
        ids = table.filter(ids, function(id) return room:getCardArea(id) ~= Card.PlayerHand end)
        fakemove = {
          from = player.id,
          toArea = Card.DiscardPile,
          moveInfo = table.map(ids, function(id) return {cardId = id, fromArea = Card.PlayerHand} end),
          moveReason = fk.ReasonGive,
        }
        room:notifyMoveCards({player}, {fakemove})
      end
    end
  end,
}
local lirang_active = fk.CreateActiveSkill{
  name = "#hs__n_lirang_active",
  mute = true,
  min_card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected, targets)
    return Fk:getCardById(to_select):getMark("lirang") > 0
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:doIndicate(player.id, {target.id})
    for _, id in ipairs(effect.cards) do
      room:setCardMark(Fk:getCardById(id), "lirang", 0)
    end
    local fakemove = {
      from = player.id,
      toArea = Card.DiscardPile,
      moveInfo = table.map(effect.cards, function(id) return {cardId = id, fromArea = Card.PlayerHand} end),
      moveReason = fk.ReasonGive,
    }
    room:notifyMoveCards({player}, {fakemove})
    room:moveCards({
      fromArea = Card.DiscardPile,
      ids = effect.cards,
      to = target.id,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonGive,
      skillName = self.name,
    })
  end,
}
lirang:addRelatedSkill(lirang_active)
kongrong:addSkill(mingshi)
kongrong:addSkill(lirang)
Fk:loadTranslationTable{
  ["hs__n_kongrong"] = "孔融",
  ["#hs__n_kongrong"] = "凛然重义",
  ["desinger:hs__n_kongrong"] = "淬毒",
  ["illustrator:hs__n_kongrong"] = "苍月白龙",

  ["hs__n_mingshi"] = "名士",
  [":hs__n_mingshi"] = "锁定技，当你受到伤害时，若来源有暗置的武将牌，你令伤害值-1。",
  ["hs__n_lirang"] = "礼让",
  [":hs__n_lirang"] = "当你的牌因弃置而移至弃牌堆后，你可将其中的至少一张牌交给其他角色。",
  ["#lirang-give"] = "礼让：你可以将这些牌分配给任意角色，点“取消”仍弃置",
  ["#hs__n_lirang_active"] = "礼让",

  ["$hs__n_mingshi1"] = "孔门之后，忠孝为先。",
  ["$hs__n_mingshi2"] = "名士之风，仁义高洁。",
  ["$hs__n_lirang1"] = "夫礼先王以承天之道，以治人之情。",
  ["$hs__n_lirang2"] = "谦者，德之柄也，让者，礼之逐也。",
  ["~hs__n_kongrong"] = "覆巢之下，岂有完卵……",
}

-----
local jiling = General(extension, "hs__n_jiling", "qun", 4)
local shuangren = fk.CreateTriggerSkill{
  name = "hs__n_shuangren",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player.phase == Player.Play and not player:isKongcheng() and table.find(player.room:getOtherPlayers(player, false), function(p)
      return not p:isKongcheng()
    end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local availableTargets = table.map(
      table.filter(room:getOtherPlayers(player, false), function(p)
        return not p:isKongcheng()
      end),
      Util.IdMapper
    )
    if #availableTargets == 0 then return false end
    local target = room:askForChoosePlayers(player, availableTargets, 1, 1, "#shuangren-ask", self.name, true)
    if #target > 0 then
      self.cost_data = target[1]
      return true
    end
    return false
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target = room:getPlayerById(self.cost_data)
    local pindian = player:pindian({target}, self.name)
    if pindian.results[target.id].winner == player then
      if player.dead then return end
      local slash = Fk:cloneCard("slash")
      if player:prohibitUse(slash) then return false end
      local availableTargets = table.map(
        table.filter(room:getOtherPlayers(player, false), function(p)
          return H.compareKingdomWith(p, target) and not player:isProhibited(p, slash)
        end),
        Util.IdMapper
      )
      if #availableTargets == 0 then return false end
      local victims = room:askForChoosePlayers(player, availableTargets, 1, 1, "#shuangren_slash-ask:" .. target.id, self.name, false)
      if #victims > 0 then
        local to = room:getPlayerById(victims[1])
        if to.dead then return false end
        room:useVirtualCard("slash", nil, player, {to}, self.name, true)
      end
    else
      room:setPlayerMark(player, "shuangren-turn", 1)
    end
  end,
}
local shuangren_prohibit = fk.CreateProhibitSkill{
  name = "#hs__n_shuangren_prohibit",
  is_prohibited = function(self, from, to, card)
    if from:hasSkill(self) then
      return from:getMark("shuangren-turn") > 0 and from ~= to
    end
  end,
}
shuangren:addRelatedSkill(shuangren_prohibit)
jiling:addSkill(shuangren)
Fk:loadTranslationTable{
  ["hs__n_jiling"] = "纪灵",
  ["#hs__n_jiling"] = "仲家的主将",
  ["illustrator:hs__n_jiling"] = "樱花闪乱",
  ["desinger:hs__n_jiling"] = "淬毒",

  ["hs__n_shuangren"] = "双刃",
  [":hs__n_shuangren"] = "出牌阶段开始时，你可与一名角色拼点。若你：赢，你视为对与其势力相同的一名角色使用【杀】；没赢，其他角色于此回合内不是你使用牌的合法目标。",
  ["#hs__n_shuangren-ask"] = "双刃：你可与一名角色拼点",
  ["#hs__n_shuangren_slash-ask"] = "双刃：你视为对与 %src 势力相同的一名角色使用【杀】",

  ["$hs__n_shuangren1"] = "仲国大将纪灵在此！",
  ["$hs__n_shuangren2"] = "吃我一记三尖两刃刀！",
  ["~hs__n_jiling"] = "额，将军为何咆哮不断……",
}

-----
local tianfeng = General(extension, "hs__n_tianfeng", "qun", 3)
local sijian = fk.CreateTriggerSkill{
  name = "hs__n_sijian",
  events = {fk.AfterCardsMove},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or not player:isKongcheng() then return end
    local ret = false
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            ret = true
            break
          end
        end
      end
    end
    if ret then
      return table.find(player.room.alive_players, function(p) return not p:isNude() end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.map(table.filter(room.alive_players, function(p) return not p:isNude() end), Util.IdMapper)
    local target = room:askForChoosePlayers(player, targets, 1, 1, "#hs__n_sijian-ask", self.name, true)
    if #target > 0 then
      self.cost_data = target[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local id = room:askForCardChosen(player, to, "he", self.name)
    room:throwCard({id}, self.name, to, player)
  end,
}
local suishi = fk.CreateTriggerSkill{
  name = "hs__n_suishi",
  frequency = Skill.Compulsory,
  events = {fk.EnterDying, fk.Death},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) or target == player then return false end
    if event == fk.EnterDying then
      return data.damage and data.damage.from and H.compareKingdomWith(data.damage.from, player)
    else
      return H.compareKingdomWith(target, player)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EnterDying then
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:broadcastSkillInvoke(self.name, 1)
      player:drawCards(1, self.name)
    else
      room:notifySkillInvoked(player, self.name, "negative")
      player:broadcastSkillInvoke(self.name, 2)
      room:loseHp(player, 1, self.name)
    end
  end,
}
tianfeng:addSkill(sijian)
tianfeng:addSkill(suishi)
Fk:loadTranslationTable{
  ["hs__n_tianfeng"] = "田丰",
  ["#hs__n_tianfeng"] = "河北瑰杰",
  ["illustrator:hs__n_tianfeng"] = "地狱许",
  ["desinger:hs__n_tianfeng"] = "淬毒",

  ["hs__n_sijian"] = "死谏",
  [":hs__n_sijian"] = "当你失去手牌后，若你没有手牌，你可弃置一名其他角色的一张牌。",
  ["hs__n_suishi"] = "随势",
  [":hs__n_suishi"] = "锁定技，①当其他角色因受到伤害而进入濒死状态时，若来源与你势力相同，你摸一张牌；②当其他角色死亡时，若其与你势力相同，你失去1点体力。",
  ["#hs__n_sijian-ask"] = "死谏：你可弃置一名其他角色的一张牌",

  ["$hs__n_sijian2"] = "忠言逆耳啊！！",
  ["$hs__n_sijian1"] = "且听我最后一言！",
  ["$hs__n_suishi1"] = "一荣俱荣！",
  ["$hs__n_suishi2"] = "一损俱损……",
  ["~hs__n_tianfeng"] = "不纳吾言而反诛吾心，奈何奈何！！",
}

-----
local panfeng = General(extension, "hs__n_panfeng", "qun", 4)
local kuangfu = fk.CreateTriggerSkill{
  name = "hs__n_kuangfu",
  events = {fk.TargetSpecified},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) and data.card and data.card.trueName == "slash" and player.phase == Player.Play and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and target == player then
      for _, p in ipairs(AimGroup:getAllTargets(data.tos)) do
        if #player.room:getPlayerById(p):getCardIds(Player.Equip) > 0 then
          return true
        end
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choice = {}
    for _ , choicePlayers in ipairs(AimGroup:getAllTargets(data.tos)) do
      if #room:getPlayerById(choicePlayers):getCardIds("e") > 0 then
        table.insert(choice, choicePlayers)
      end
    end
    local p = room:askForChoosePlayers(player, choice, 1, 1, "#hs__n_kuangfu-choice", self.name, true)
    if #p == 0 then return end
    local card = room:askForCardChosen(player, room:getPlayerById(p[1]), "e", self.name)
    room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    data.extra_data = data.extra_data or {}
    data.extra_data.hs__n_kuangfuUser = player.id
  end,
}
local kuangfu_delay = fk.CreateTriggerSkill{
  name = "#hs__n_kuangfu_delay",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function (self, event, target, player, data)
    return (data.extra_data or {}).hs__n_kuangfuUser == player.id and not data.damageDealt
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:askForDiscard(player, 2, 2, true, self.name, false)
  end,
}
kuangfu:addRelatedSkill(kuangfu_delay)
panfeng:addSkill(kuangfu)
Fk:loadTranslationTable{
  ["hs__n_panfeng"] = "潘凤",
  ["#hs__n_panfeng"] = "联军上将",
  ["illustrator:hs__n_panfeng"] = "凡果",

  ["hs__n_kuangfu"] = "狂斧",
  [":hs__n_kuangfu"] = "当你于出牌阶段内使用【杀】指定目标后，若你于此阶段内未发动过此技能，你可获得此牌其中一个目标角色装备区内的一张牌，然后此牌结算后，若此牌未造成过伤害，你弃置两张牌。",

  ["#hs__n_kuangfu_delay"] = "狂斧",
  ["#hs__n_kuangfu-choice"] = "狂斧：选择一名装备区内有牌且是此牌目标的角色，获得其装备区内一张牌",
  ["$hs__n_kuangfu1"] = "吾乃上将潘凤，可斩华雄！",
  ["$hs__n_kuangfu2"] = "这家伙，还是给我用吧！",
  ["~hs__n_panfeng"] = "潘凤又被华雄斩啦。",
}

-----
local zoushi = General(extension, "hs__n_zoushi", "qun", 3, 3, General.Female)
local huoshui = fk.CreateTriggerSkill{ -- FIXME
  name = "hs__n_huoshui",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.TurnStart, fk.GeneralRevealed, fk.EventAcquireSkill, fk.EventLoseSkill, fk.Deathed, fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target ~= player or player.room.current ~= player then return false end
    if event == fk.TurnStart then
      return player:hasShownSkill(self)
    end
    if event == fk.EventAcquireSkill or event == fk.EventLoseSkill then
      return data == self
    elseif event == fk.GeneralRevealed then
      if player:hasSkill(self) then
        for _, v in pairs(data) do
          if table.contains(Fk.generals[v]:getSkillNameList(), self.name) then return true end
        end
      end
    elseif event == fk.CardUsing then
      return player:hasSkill(self)  and (data.card.trueName == "slash" or data.card.trueName == "archery_attack")
    else
      return player:hasSkill(self, true, true)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if table.contains({fk.TurnStart, fk.GeneralRevealed, fk.EventAcquireSkill}, event) then
      local targets = {}
      for _, p in ipairs(room:getOtherPlayers(player, false)) do
        room:setPlayerMark(p, "@@huoshui-turn", 1)
        local record = p:getTableMark(MarkEnum.RevealProhibited .. "-turn")
        table.insertTable(record, {"m", "d"})
        room:setPlayerMark(p, MarkEnum.RevealProhibited .. "-turn", record)
        table.insert(targets, p.id)
      end
      room:doIndicate(player.id, targets)
    elseif event == fk.CardUsing then
      local targets = table.filter(room.alive_players, function(p) return (not H.compareKingdomWith(p, player)) and H.getGeneralsRevealedNum(p) == 1 end)
      if #targets > 0 then
        data.disresponsiveList = data.disresponsiveList or {}
        for _, p in ipairs(targets) do
          table.insertIfNeed(data.disresponsiveList, p.id)
        end
      end
    else
      for _, p in ipairs(room:getOtherPlayers(player, false)) do
        room:setPlayerMark(p, "@@huoshui-turn", 0)
        local record = p:getTableMark(MarkEnum.RevealProhibited .. "-turn")
        table.removeOne(record, "m")
        table.removeOne(record, "d")
        if #record == 0 then record = 0 end
        room:setPlayerMark(p, MarkEnum.RevealProhibited .. "-turn", record)
      end
    end
  end,
}
local qingcheng = fk.CreateActiveSkill{
  name = "hs__n_qingcheng",
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  card_filter = function(self, to_select, selected, targets)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if #selected > 0 or #selected_cards == 0 then return false end --TODO
    local target = Fk:currentRoom():getPlayerById(to_select)
    return to_select ~= Self.id and target.general ~= "anjiang" and target.deputyGeneral ~= "anjiang"
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local ret = false
    if Fk:getCardById(effect.cards[1]).type == Card.TypeEquip then
      ret = true
    end
    room:throwCard(effect.cards, self.name, player, player)
    H.doHideGeneral(room, player, target, self.name)
    if ret and not player.dead then
      local targets = table.filter(room.alive_players, function(p) return p.general ~= "anjiang" and p.deputyGeneral ~= "anjiang" and p ~= player and p ~= target end)
      if #targets == 0 then return false end
      local to = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#qingcheng-again", self.name, true)
      if #to > 0 then
        target = room:getPlayerById(to[1])
        H.doHideGeneral(room, player, target, self.name)
      end
    end
  end,
}
zoushi:addSkill(huoshui)
zoushi:addSkill(qingcheng)
Fk:loadTranslationTable{
  ["hs__n_zoushi"] = "邹氏",
  ["hs__n_huoshui"] = "祸水",
  [":hs__n_huoshui"] = "锁定技，你的回合内：1.其他角色不能明置其武将牌；2.当你使用【杀】或【万箭齐发】时，你令此牌不能被与你势力不同且有暗置武将牌的角色响应。",
  ["hs__n_qingcheng"] = "倾城",
  [":hs__n_qingcheng"] = "出牌阶段，你可弃置一张黑色牌并选择一名武将牌均明置的其他角色，然后你暗置其一张武将牌。然后若你以此法弃置的牌是黑色装备牌，则你可再选择另一名武将牌均明置的其他角色，暗置其一张武将牌。",

  ["@@huoshui-turn"] = "祸水",
  ["#qingcheng-again"] = "倾城：你可再选择另一名武将牌均明置的其他角色，暗置其一张武将牌",

  ["$hs__n_huoshui1"] = "走不动了嘛？" ,
  ["$hs__n_huoshui2"] = "别走了在玩一会嘛？" ,
  ["$hs__n_qingcheng1"] = "我和你们真是投缘啊。",
  ["$hs__n_qingcheng2"] = "哼，眼睛都直了呀。",
  ["~hs__n_zoushi"] = "年老色衰了吗？",
}

-----------
-- 军令四
local command4_prohibit = fk.CreateProhibitSkill{
  name = "#command4_prohibit",
  -- global = true,
  prohibit_use = function(self, player, card)
    if player:getMark("@@command4_effect-turn") > 0 then
      local subcards = card:isVirtual() and card.subcards or {card.id}
      return #subcards > 0 and table.every(subcards, function(id) return table.contains(player:getCardIds(Player.Hand), id) end)
    end
  end,
  prohibit_response = function(self, player, card)
    if player:getMark("@@command4_effect-turn") > 0 then
      local subcards = card:isVirtual() and card.subcards or {card.id}
      return #subcards > 0 and table.every(subcards, function(id) return table.contains(player:getCardIds(Player.Hand), id) end)
    end
  end,
}
Fk:addSkill(command4_prohibit)

-- 军令五 你不准回血！
local command5_cannotrecover = fk.CreateTriggerSkill{
  name = "#command5_cannotrecover",
  -- global = true,
  refresh_events = {fk.PreHpRecover},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@command5_effect-turn") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    data.num = 0
    return true
  end,
}
Fk:addSkill(command5_cannotrecover)

-- 军令六
local command6_select = fk.CreateActiveSkill{
  name = "#command6_select",
  can_use = Util.FalseFunc,
  target_num = 0,
  card_num = function()
    local x = 0
    if #Self.player_cards[Player.Hand] > 0 then x = x + 1 end
    if #Self.player_cards[Player.Equip] > 0 then x = x + 1 end
    return x
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 1 then
      return (Fk:currentRoom():getCardArea(to_select) == Card.PlayerEquip) ~=
      (Fk:currentRoom():getCardArea(selected[1]) == Card.PlayerEquip)
    end
    return #selected == 0
  end,
}
Fk:addSkill(command6_select)
Fk:loadTranslationTable{
  ["#command6_select"] = "军令",
}

local vanguradSkill = fk.CreateActiveSkill{
  name = "vanguard_skill&",
  prompt = "#vanguard_skill&",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:getMark("@!vanguard") > 0
  end,
  card_filter = Util.FalseFunc,
  target_num = function()
    return table.find(Fk:currentRoom().alive_players, function(p) return (p.general == "anjiang" or p.deputyGeneral == "anjiang") and p ~= Self end) and 1 or 0
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if to_select ~= Self.id and #selected == 0 and table.find(Fk:currentRoom().alive_players, function(p) return (p.general == "anjiang" or p.deputyGeneral == "anjiang") and p ~= Self end) then
      local target = Fk:currentRoom():getPlayerById(to_select)
      return target.general == "anjiang" or target.deputyGeneral == "anjiang"
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:removePlayerMark(player, "@!vanguard")
    if player:getMark("@!vanguard") == 0 then
      player:loseFakeSkill("vanguard_skill&")
      -- room:handleAddLoseSkills(player, "-vanguard_skill&", nil, false, true)
    end
    local num = 4 - player:getHandcardNum()
    if num > 0 then
      player:drawCards(num, self.name)
    end
    if #effect.tos == 0 then return false end
    local target = room:getPlayerById(effect.tos[1])
    local choices = {"known_both_main", "known_both_deputy"}
    if target.general ~= "anjiang" then
      table.remove(choices, 1)
    end
    if target.deputyGeneral ~= "anjiang" then
      table.remove(choices)
    end
    if #choices == 0 then return end
    local choice = room:askForChoice(player, choices, self.name, "#known_both-choice::"..target.id, false)
    local general = choice == "known_both_main" and {target:getMark("__heg_general"), target.deputyGeneral, target.seat} or {target.general, target:getMark("__heg_deputy"), target.seat}
    room:askForCustomDialog(player, self.name, "packages/new_heg/qml/KnownBothBox.qml", general)
  end,
}
Fk:addSkill(vanguradSkill)
Fk:loadTranslationTable{
  ["vanguard_skill&"] = "先驱",
  ["#vanguard_skill&"] = "你可弃一枚“先驱”，将手牌摸至4张，观看一名其他角色的一张暗置武将牌",
  [":vanguard_skill&"] = "出牌阶段，你可弃一枚“先驱”，将手牌摸至4张，观看一名其他角色的一张暗置武将牌。",
  ["vanguard"] = "先驱",
}


local yinyangfishSkill = fk.CreateActiveSkill{
  name = "yinyangfish_skill&",
  prompt = "#yinyangfish_skill&",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:getMark("@!yinyangfish") > 0
  end,
  card_filter = Util.FalseFunc,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:removePlayerMark(player, "@!yinyangfish")
    if player:getMark("@!yinyangfish") == 0 then
      player:loseFakeSkill("yinyangfish_skill&")
    end
    player:drawCards(1, self.name)
  end,
}
local yinyangfishMax = fk.CreateTriggerSkill{
  name = "#yinyangfish_max&",
  priority = 0.1,
  anim_type = "defensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Discard and player:hasSkill(self) and player:getMark("@!yinyangfish") > 0 and player:getHandcardNum() > player:getMaxCards()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#yinyangfish_max-ask")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@!yinyangfish")
    if player:getMark("@!yinyangfish") == 0 then
      player:loseFakeSkill("yinyangfish_skill&")
    end
    room:addPlayerMark(target, MarkEnum.AddMaxCardsInTurn, 2)
    room:broadcastProperty(player, "MaxCards")
  end,
}
yinyangfishSkill:addRelatedSkill(yinyangfishMax)
Fk:addSkill(yinyangfishSkill)
Fk:loadTranslationTable{
  ["yinyangfish_skill&"] = "阴阳鱼",
  ["#yinyangfish_skill&"] = "你可弃一枚“阴阳鱼”，摸一张牌",
  ["#yinyangfish_max&"] = "阴阳鱼",
  ["#yinyangfish_max-ask"] = "你可弃一枚“阴阳鱼”，此回合手牌上限+2",
  [":yinyangfish_skill&"] = "出牌阶段，你可弃一枚“阴阳鱼”，摸一张牌；弃牌阶段开始时，你可弃一枚“阴阳鱼”，此回合手牌上限+2。",
  ["yinyangfish"] = "阴阳鱼",
}

local companionSkill = fk.CreateActiveSkill{
  name = "companion_skill&",
  prompt = "#companion_skill&",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:getMark("@!companion") > 0
  end,
  card_filter = Util.FalseFunc,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:removePlayerMark(player, "@!companion")
    if player:getMark("@!companion") == 0 then
      player:loseFakeSkill("companion_skill&")
      player:loseFakeSkill("companion_peach&")
      -- room:handleAddLoseSkills(player, "-companion_skill&|-companion_peach&", nil, false, true)
    end
    player:drawCards(2, self.name)
  end,
}
local companionPeach = fk.CreateViewAsSkill{
  name = "companion_peach&",
  anim_type = "support",
  prompt = "#companion_peach&",
  pattern = "peach",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local c = Fk:cloneCard("peach")
    c.skillName = self.name
    return c
  end,
  before_use = function(self, player)
    local room = player.room
    room:removePlayerMark(player, "@!companion")
    if player:getMark("@!companion") == 0 then
      player:loseFakeSkill("companion_skill&")
      player:loseFakeSkill("companion_peach&")
    end
  end,
  enabled_at_play = function(self, player)
    return player:getMark("@!companion") > 0
  end,
  enabled_at_response = function(self, player)
    return player:getMark("@!companion") > 0
  end,
}
Fk:addSkill(companionSkill)
Fk:addSkill(companionPeach)
Fk:loadTranslationTable{
  ["companion_skill&"] = "珠联[摸]",
  ["#companion_skill&"] = "你可弃一枚“珠联璧合”，摸两张牌",
  [":companion_skill&"] = "出牌阶段，你可弃一枚“珠联璧合”，摸两张牌。",
  ["companion_peach&"] = "珠联[桃]",
  [":companion_peach&"] = "你可弃一枚“珠联璧合”，视为使用【桃】。",
  ["#companion_peach&"] = "你可弃一枚“珠联璧合”，视为使用【桃】",
  ["companion"] = "珠联璧合",
}

local wildDraw = fk.CreateActiveSkill{
  name = "wild_draw&",
  prompt = "#wild_draw&",
  anim_type = "drawcard",
  can_use = function(self, player)
    return player:getMark("@!wild") > 0
  end,
  interaction = UI.ComboBox { choices = {"wild_vanguard", "wild_companion", "wild_yinyangfish"} },
  card_filter = Util.FalseFunc,
  target_num = function(self)
    return self.interaction.data == "wild_vanguard" and table.find(Fk:currentRoom().alive_players, function(p) return (p.general == "anjiang" or p.deputyGeneral == "anjiang") and p ~= Self end) and 1 or 0 
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    if self.interaction.data == "wild_vanguard" and to_select ~= Self.id and #selected == 0 and table.find(Fk:currentRoom().alive_players, function(p) return (p.general == "anjiang" or p.deputyGeneral == "anjiang") and p ~= Self end) then
      local target = Fk:currentRoom():getPlayerById(to_select)
      return target.general == "anjiang" or target.deputyGeneral == "anjiang"
    end
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:removePlayerMark(player, "@!wild")
    if player:getMark("@!wild") == 0 then
      player:loseFakeSkill("wild_draw&")
      player:loseFakeSkill("wild_peach&")
    end
    local pattern = self.interaction.data
    if pattern == "wild_companion" then
      player:drawCards(2, self.name)
    elseif pattern == "wild_yinyangfish" then
      player:drawCards(1, self.name)
    elseif pattern == "wild_vanguard" then
      local num = 4 - player:getHandcardNum()
      if num > 0 then
        player:drawCards(num, self.name)
      end
      if #effect.tos == 0 then return false end
      local target = room:getPlayerById(effect.tos[1])
      local choices = {"known_both_main", "known_both_deputy"}
      if target.general ~= "anjiang" then
        table.remove(choices, 1)
      end
      if target.deputyGeneral ~= "anjiang" then
        table.remove(choices)
      end
      if #choices == 0 then return end
      local choice = room:askForChoice(player, choices, self.name, "#known_both-choice::"..target.id, false)
      local general = choice == "known_both_main" and {target:getMark("__heg_general"), target.deputyGeneral, target.seat} or {target.general, target:getMark("__heg_deputy"), target.seat}
      room:askForCustomDialog(player, self.name, "packages/new_heg/qml/KnownBothBox.qml", general)
    end
  end,
}
local wildPeach = fk.CreateViewAsSkill{
  name = "wild_peach&",
  anim_type = "support",
  prompt = "#wild_peach&",
  pattern = "peach",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local c = Fk:cloneCard("peach")
    c.skillName = self.name
    return c
  end,
  before_use = function(self, player)
    local room = player.room
    room:removePlayerMark(player, "@!wild")
    if player:getMark("@!wild") == 0 then
      player:loseFakeSkill("wild_draw&")
      player:loseFakeSkill("wild_peach&")
    end
  end,
  enabled_at_play = function(self, player)
    return player:getMark("@!wild") > 0
  end,
  enabled_at_response = function(self, player)
    return player:getMark("@!wild") > 0
  end,
}
local wildMax = fk.CreateTriggerSkill{
  name = "#wild_max&",
  priority = 0.09,
  anim_type = "defensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player.phase == Player.Discard and player:hasSkill(self) and player:getMark("@!wild") > 0 and player:getHandcardNum() > player:getMaxCards()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#wild_max-ask")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@!wild")
    if player:getMark("@!wild") == 0 then
      player:loseFakeSkill("wild_draw&")
      player:loseFakeSkill("wild_peach&")
    end
    room:addPlayerMark(target, MarkEnum.AddMaxCardsInTurn, 2)
  end,
}
wildDraw:addRelatedSkill(wildMax)
Fk:addSkill(wildDraw)
Fk:addSkill(wildPeach)

Fk:loadTranslationTable{
  ["wild_draw&"] = "野心[牌]",
  [":wild_draw&"] = "你可弃一枚“野心家”，执行“先驱”、“阴阳鱼”或“珠联璧合”的效果。",
  ["#wild_draw&"] = "你可将“野心家”当一种标记弃置并执行其效果（点击左侧选项框展开）",
  ["wild_vanguard"] = "将手牌摸至4张，观看一张暗置武将牌",
  ["wild_yinyangfish"] = "摸一张牌",
  ["wild_companion"] = "摸两张牌",

  ["wild_peach&"] = "野心[桃]",
  [":wild_peach&"] = "你可弃一枚“野心家”，视为使用【桃】。",
  ["#wild_peach&"] = "你可弃一枚“野心家”，视为使用【桃】",

  ["#wild_max&"] = "野心家[手牌上限]",
  ["#wild_max-ask"] = "你可弃一枚“野心家”，此回合手牌上限+2",
}

local battleRoyalVS = fk.CreateViewAsSkill{
  name = "battle_royal&",
  pattern = "slash,jink",
  expand_pile = "carriage&",
  interaction = function()
    local names = {}
    if Fk.currentResponsePattern == nil and Self:canUse(Fk:cloneCard("slash")) then
      table.insertIfNeed(names, "slash")
    else
      for _, name in ipairs({"slash", "jink"}) do
        if Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard(name)) then
          table.insertIfNeed(names, name)
        end
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "peach"
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
  enabled_at_play = function(self, player)
    if player:getMark("_heg__BattleRoyalMode_ignore") ~= 0 then return false end
    return table.find(player:getHandlyIds(true), function (id)
      return Fk:getCardById(id).trueName == "peach"
    end)
  end,
  enabled_at_response = function(self, player)
    if player:getMark("_heg__BattleRoyalMode_ignore") ~= 0 then return false end
    return table.find(player:getHandlyIds(true), function (id)
      return Fk:getCardById(id).trueName == "peach"
    end)
  end,
}
local battleRoyalProhibit = fk.CreateProhibitSkill{
  name = "#battle_royal_prohibit&",
  prohibit_use = function(self, player, card)
    if not card or card.trueName ~= "peach" or #card.skillNames > 0 or player:getMark("_heg__BattleRoyalMode_ignore") ~= 0 then return false end
    local subcards = Card:getIdList(card)
    return #subcards > 0 and table.every(subcards, function(id)
      return table.contains(player:getHandlyIds(true), id)
    end)
  end
}
battleRoyalVS:addRelatedSkill(battleRoyalProhibit)
Fk:addSkill(battleRoyalVS)
Fk:loadTranslationTable{
  ["battle_royal&"] = "鏖战",
  [":battle_royal&"] = "非转化的【桃】只能当【杀】或【闪】使用或打出。",
  ["#battle_royal_prohibit&"] = "鏖战",

  ["_heg__BattleRoyalMode_ignore"] = "无视鏖战",

}

return extension
